简体   繁体   English

消费Json数据ProcessRequest winrt

[英]Consuming Json data ProcessRequest winrt

I am working on consuming Json data in Windows RT. 我正在使用Windows RT中的Json数据。 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: 但是,在ProcessRequest我看到一条错误消息:

no suitable method found to override 找不到适合的方法来覆盖

I should use System.Web.HttpContext but I can't use it, because of Windows RT. 我应该使用System.Web.HttpContext但是由于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. 现在,您有了一个名为json witch的变量,其中包含来自服务器的响应,您现在就可以对其进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM