簡體   English   中英

消費Json數據ProcessRequest winrt

[英]Consuming Json data ProcessRequest winrt

我正在使用Windows RT中的Json數據。 我按照以下鏈接執行了以下步驟

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而不能使用。 我該如何解決?

試試這個:

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 witch的變量,其中包含來自服務器的響應,您現在就可以對其進行處理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM