我有这个代码:
private HttpWebRequest request;
private HttpWebResponse wResponse;
private CookieContainer cookieContainer = new CookieContainer();
#region PRIVATE METHODS
private void RunRequest(string url)
{
request = HttpWebRequest.Create(new Uri(url)) as HttpWebRequest;
request.UserAgent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.205 Safari/534.16";
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = cookieContainer;
request.Method = "GET";
StartWebRequest(request);
//Do smthng
while (wResponse == null) { }
}
private void StartWebRequest(HttpWebRequest request)
{
request.BeginGetResponse(FinishWebRequest, request);
}
private void FinishWebRequest(IAsyncResult result)
{
wResponse = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse;
}
#endregion
并且 wRequest 变量没有填充任何响应。在 AsyncState 我有这个:
可能是什么问题呢?
ps 相同的代码在桌面应用程序上运行良好。
谢谢,帕维尔。