i made an app in windows phone successfully & now i want to make it for windows 8 store app but i stuck on a point where i want to my web service in store app.
I use webclient in WP but i don't know anything about how to access web service in Windows 8 store app. My web service return data in json format i deserialize & store in a variable in WP & i use post method . but how it would be done in Windows 8 store app. what would i use for windows 8 in place of Webclient.
i post my windows phone code
Code
private void PostData()Code
{Code
Uri uri = new Uri(my web service url);Code
string data = "device_id=" + val + "&quiz_type=all";Code
WebClient wc = new WebClient();Code
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";Code
wc.UploadStringAsync(uri, data);Code
wc.UploadStringCompleted += wc_UploadComplete;Code
}Code
public void wc_UploadComplete(object sender, UploadStringCompletedEventArgs e)Code
{Code
var rootObject = JsonConvert.DeserializeObject(e.Result);Code
}
Ramprasath R K7 reputationPosted Apr 30, 2014, 12:21 AM EDT
var client = new HttpClient();
string data = "device_id=" + val + "&quiz_type=all";
var postContent = new StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded");
// send request asynchronously and continue when complete
var response = await client.PostAsync(address, postContent);
// check that response was successful or throw exception response.EnsureSuccessStatusCode();
//Read the JSON response
var content = await response.Content.ReadAsStringAsync();