【问题标题】:Consuming Json data ProcessRequest winrt消费Json数据ProcessRequest winrt
【发布时间】:2015-08-25 11:07:11
【问题描述】:

我正致力于在 Windows RT 中使用 Json 数据。我按照link 的步骤如下

protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken)
{
    if(request.Method==HttpMethod.Get)
    {
        request.Headers.Add("abcustom", "reqvalue");
    }
    return request;
 }

但是,ProcessRequest 我有一个错误,上面写着:

找不到合适的方法来覆盖

我应该使用System.Web.HttpContext,但我不能使用它,因为 Windows RT。我该如何解决?

【问题讨论】:

    标签: c# json web-services windows-runtime overriding


    【解决方案1】:

    试试这个:

    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();
    

    现在您有一个名为 json 的变量,其中包含来自服务器的响应,您现在可以对其进行处理。

    【讨论】:

      猜你喜欢
      • 2019-04-19
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 2018-08-04
      • 2021-08-20
      • 1970-01-01
      相关资源
      最近更新 更多