Sunday, 15 April 2012

windows phone - How to get response body from httpclient c# when doing multipart -


I am trying to post multipart data using System.Net.Http.HttpClient, received feedback 200 is fine.

Here is the method I used:

  Public async job postmultiPart () {var client = new HTTP client (); Client.DefaultRequestHeaders.TryAddWithoutValidation ("content-type", "multicast / form-data"); // This PostData MultipartFormDataContent Content = New MultipartFormDataContent (); Content.Add (new string content ("12", encoding. UTF8), "UserID"); Content.Add (new string content ("78", encoding. UTF8), "noofetende"); Content.Add (new string content ("Chennai", encoding. UTF8), "location name"); Content.Add (new string content ("32.56", encoding. UTF8), "longitude"); Content.Add (new string content ("32.56", encoding. UTF8), "latitude"); Console.Write (content); // upload the file information and upload to ensure a result. // This will throw an exception if the service does not return valid valid status code to the customer. PostAsync (fileUploadUrl, content). With full ((PostTask) => {postTask.Result.EnsureSuccessStatusCode ();}); }  
  • How to obtain a response body from this method?
  • To resonate John (who does not disagree with John only), formerly - async / await ( continue ) The world of async / wait was not found with the world.

    To get the body of the reaction as a string, you have to wait another:

      var response = wait client.PostAsync (fileUploadUrl, content); Response.EnsureSuccessStatusCode (); Var body = Waiting for the result. Content RedAssressingSync ();  

No comments:

Post a Comment