我正在创建一个Metro App,它向Web服务器发出HTTP Post请求以获取JSON数据。最初我使用相同的代码登录到Web服务器,HTTP Post请求返回正常。只是后来我遇到了一个问题,当我调用SendAsync()方法时代码挂起。
我使用wireshark查看网络流量,我确实看到服务器返回响应。所以我不确定为什么电话没有完成。有人有主意吗?
以下是我正在使用的代码:
var httpHandler = new HttpClientHandler();
httpHandler.CookieContainer = __CookieJar;
var httpClient = new HttpClient(httpHandler);
UserAgentDetails userAgent = UserAgentDetails.GetInstance();
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent.UserAgentString);
foreach (string key in __colHeaders)
httpClient.DefaultRequestHeaders.Add(key, __colHeaders[key]);
var content = new StringContent(postData);
if (contentType != null && contentType.Length > 0)
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
var requestMsg = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
requestMsg.Content = content;
requestMsg.Headers.TransferEncodingChunked = true;
var responseMsg = await httpClient.SendAsync(requestMsg);
// no return from method after logon