2012-05-03 72 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