【发布时间】:2011-06-04 19:01:16
【问题描述】:
我正在尝试创建一个执行 HTTP 的简单应用程序 单击按钮时的请求/响应。这是我得到的整个代码 参考书:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace emulator2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
Uri l_Uri = new Uri("http://www.testing.com");
HttpWebRequest l_WebReq = (HttpWebRequest)WebRequest.Create(l_Uri);
HttpWebResponse l_WebResponse =
(HttpWebResponse)l_WebReq.GetResponse();
Stream l_responseStream = l_WebResponse.GetResponseStream();
StreamReader l_SReader = new StreamReader(l_responseStream);
string resultstring = l_SReader.ReadToEnd();
Console.WriteLine(resultstring);
}
}
}
让我困惑的是,当我移动整个代码块时 到 Windows 应用程序,它工作正常。但是当我在设备上使用它时 应用程序,它只是给我一个错误。以下是详细信息 错误:
System.Net.WebException 未处理 Message="无法建立 连接到网络。” StackTrace:在 System.Net.HttpWebRequest.finishGetResponse() 在 System.Net.HttpWebRequest.GetResponse() 在 emulator2.Form1.button1_Click() 在 System.Windows.Forms.Control.OnClick() 在 System.Windows.Forms.Button.OnClick() 在 System.Windows.Forms.ButtonBase.WnProc() 在 System.Windows.Forms.Control._InternalWnProc() 在 Microsoft.AGL.Forms.EVL.EnterMainLoop() 在 System.Windows.Forms.Application.Run() at emulator2.Program.Main()
这一行的错误点:
HttpWebResponse l_WebResponse = (HttpWebResponse)l_WebReq.GetResponse();
有人知道如何解决这个问题吗?我需要得到这个 很快就解决了..所以非常感谢您提供的任何帮助!谢谢!
【问题讨论】:
标签: c# mobile web-applications windows-mobile