2015-08-25 74 views
1

我正在使用Windows RT中的Json數據。我跟着從這個link步驟如下消費Json數據ProcessRequest winrt

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,無法使用它。我該如何解決它?

回答

0

嘗試使用這樣的:

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女巫變量包含從服務器的響應,並且現在可以處理它。