Hey Rahul,
It's sound like you are building windows app store application for windows phone 8.1. In this case use HttpClient instead of WebClient. WebClient is available for Windows Phone Silverlight 8.1 apps. Windows Phone Runtime apps use Windows.Web.Http.HttpClient.
see the following code snippet that call a json auth post api as :
public static async Task<string> AuthenticateUserAsync(string UserID, string Password) {
using (var client = new HttpClient()) {
client.BaseAddress = new Uri("https://www.exaple.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response;
// HTTP POST
response = await client.PostAsync("api/Auth", new StringContent("[\""+ UserID + "\",\"" + Password + "\"]", Encoding.UTF8, "application/json") );
if (response.IsSuccessStatusCode) {
return response.Content.ReadAsStringAsync().Result;
} else {
return response.StatusCode.ToString();
}
}
}
Posted On:
05-Jun-2016 05:48