2011-03-14 132 views
0

我寫了一個程序,它發送特定站點的請求並獲取響應。它適當地與本地主機一起運行。但是,如果我把www.google.com然後提示錯誤爲 「遙遠而明亮服務器返回錯誤:未找到」遠程服務器返回錯誤:未找到

****代碼* ** * *

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 
using System.IO; 


namespace WindowsPhoneApplication2 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     // Constructor 
     public MainPage() 
     { 
      InitializeComponent(); 

      var request = (HttpWebRequest)WebRequest.Create(new Uri(@"http://www.google.com")); 

      request.BeginGetResponse(r => 
      { 
       var httpRequest = (HttpWebRequest)r.AsyncState; 
       var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(r); 
       using (var reader = new StreamReader(httpResponse.GetResponseStream())) 
       { 
        var response = reader.ReadToEnd(); 
        Deployment.Current.Dispatcher.BeginInvoke(new Action(() => { textBox1.Text = response; })); 
       } 
      }, request); 

     } 


    } 
} 

請告訴我soultion thanx提前

+0

它在模擬器中的IE中工作嗎?嘗試通過NetworkInterface.GetIsNetworkAvailable()檢查連接是否可用 – Robert 2011-03-14 10:50:20

回答

1

您的代碼適用於我。

您可以通過設備/模擬器的IE訪問Google嗎?
我懷疑這是您本地的網絡問題,與設備無關。

相關問題