我写了一个程序,它发送特定网站的请求并获得响应。它与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);
}
}
}
答案 0 :(得分:1)
您的代码适合我。
您可以在设备/模拟器上从IE访问Google吗? 我怀疑这是您本地的网络问题,与设备无关。