我正在创建一个 Metro 应用程序,它向网络服务器发出 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