远程服务器返回错误:未找到

时间:2011-03-14 09:38:54

标签: windows-phone-7

我写了一个程序,它发送特定网站的请求并获得响应。它与localhost一起正常运行。但是,如果我把www.google.com然后它提示错误为“remore服务器返回错误:找不到”

**** 代码 * ** < EM> * *

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); 

        }


    }
}

请告诉我灵魂 提前谢谢

1 个答案:

答案 0 :(得分:1)

您的代码适合我。

您可以在设备/模拟器上从IE访问Google吗? 我怀疑这是您本地的网络问题,与设备无关。