I am working on consuming Json data in Windows RT. I followed steps from this link as follows
protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken)
{
if(request.Method==HttpMethod.Get)
{
request.Headers.Add("abcustom", "reqvalue");
}
return request;
}
But, at ProcessRequest
I have an error which says:
no suitable method found to override
I should use System.Web.HttpContext
but I can't use it, because of Windows RT. How can I fix it?
Try use this:
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://www.domain.com");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/YourPath");
request.Content = new StringContent(jsonStringToSend, Encoding.UTF8, "application/json");
HttpResponseMessage response = await httpClient.SendAsync(request);
string json = await response.Content.ReadAsStringAsync();
now you have a variable called json witch contains the response from the server, and you can process it now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.