2017-10-08 13 views
0

我正在與xamarin.forms和System.Net.Http;uri太長,當我嘗試發送一個base64使用xamarin表格

我使用後的功能是這個發送照片:

public static async Task<String> PostImagemAsync(User user) 
    { 
     using (var client = new HttpClient()) 
     { 
      try 
      { 

       var values = new List<KeyValuePair<string, string>>(0); 
       values.Add(new KeyValuePair<string, string>("email", user.usua_login)); 
       values.Add(new KeyValuePair<string, string>("senha", user.usua_senha)); 
       values.Add(new KeyValuePair<string, string>("foto", user.cont_imagem)); 
       values.Add(new KeyValuePair<string, string>("json", "1")); 

       var content = new FormUrlEncodedContent(values); 

       HttpResponseMessage response = await client.PostAsync("http://ws.neosuite.com.br/login.asmx/foto", content); 

       var json = response.Content.ReadAsStringAsync().Result; 

       json = json.Substring(json.IndexOf('[')); 
       json = json.Substring(0, json.LastIndexOf(']') + 1); 

       var userImage = JsonConvert.DeserializeObject<List<User>>(json); 

       return userImage[0].cont_imagem; 
      } 

      catch (Exception ex) 
      { 
       Debug.WriteLine(ex.Message); 
       return null; 
      } 
     } 
    } 

我的圖像(照片)是一個base64當我試圖把它它我得到這個錯誤:

URI無效:Uri字符串太長。

如何解決?

+0

這是在客戶端上的異常,或從服務器的錯誤? – Jason

+0

我讀過它,看來我的base64字符串對於uri來說很大 –

回答

1

無需添加您的帖子內容爲網址,使用添加到身體下面的代碼

var uri = new Uri (string.Format ("http://ws.neosuite.com.br/login.asmx/foto", string.Empty)); 

var json = JsonConvert.SerializeObject (user);//user object or you can create your own jason here 
var content = new StringContent (json, Encoding.UTF8, "application/json"); 
var response = await client.PostAsync (uri, content); 
相關問題