我正在使用任务发送 Httprequests 并捕获他们的响应。在我的代码中,我想知道 (HttpWebResponse)t.Result 和 HttpWebResponse response = (HttpWebResponse)myReq.GetResponse 之间的真正区别是什么,
这是实际代码:
public void pageCheck(WebSite webParam){
//SomeCode omitted
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse response = null;
try{
Task<WebResponse> task = Task<WebResponse>.Factory.FromAsync(
myReq.BeginGetResponse,myReq.EndGetResponse,null);
task.ContinueWith(t =>
{
//some code omitted
var responseCode = (HttpWebResponse) t.Result;
//do some things with response code
response = (HttpWebResponse)myReq.GetResponse();
//other code omitted
});
}
}