2012-05-03 80 views
0

我打电话给我的方法就像HttpWebRequest,它会给我这样的错误 我的代码是这样的。错误WP7 HttpWebRequest调用方法

HttpWebRequest objHttpWebRequest = System.Net.WebRequest.CreateHttp("http://url"); 
     objHttpWebRequest.BeginGetResponse(r => 
     { 
      WebResponse response = null; 
      try 
      { 
       response = objHttpWebRequest.EndGetResponse(r); //End Async Call to the URL 
       using (var stream = response.GetResponseStream()) 
       using (var reader = new StreamReader(stream)) //get data in StreamReader 
       { 
        string contents = reader.ReadToEnd(); //read content from reader and store it in content 
        XElement xmlResult = XElement.Parse(contents); 
        AEGAPI.clsGlobal.RandomToken = xmlResult.Value; 
       } 

Error Snap

我的错误报告是

System.NotSupportedException occurred 
    Message=Timeouts are not supported on this stream. 
    StackTrace: 
     at System.IO.Stream.get_WriteTimeout() 
     at MS.Internal.InternalNetworkStream.get_Length() 
     at System.IO.StreamReader.ReadToEnd() 
     at AEGAPI.clsAEGAPI.<>c__DisplayClass3.<Authenticate>b__0(IAsyncResult r) 
     at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2) 
     at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadPool.WorkItem.doWork(Object o) 
     at System.Threading.Timer.ring() 

感谢您的帮助!

+0

你有什么样的错误? –

+0

此流不支持超时。 –

+0

哦,我明白了。我第一次遇到了麻烦。 –

回答

1

使用WebClient.DownloadStringAsync()会更简单吗?

void startDownload(Uri url) 
{ 
    WebClient wc = new WebClient(); 
    wc.DownloadStringCompleted += MyMethod; 
    wc.DownloadStringAsync(url); 
} 
void MyMethod(object sender, DownloadStringCompletedEventArgs e) 
{ 
    var contents = e.Result; 
    XElement xmlResult = XElement.Parse(contents); 
    AEGAPI.clsGlobal.RandomToken = xmlResult.Value; 
} 
+0

: - 谢谢你的回复,你可以帮我多一点我对这个请求有点困惑我把我的整个代码检索数据只是你可以纠正我的代码,那么这将是对我的巨大帮助我得到这个问题至少需要3天,所以我可以继续。 –

+0

没有比我发布的更多。在你寻求更多帮助之前,请至少出发。 – ZombieSheep