winform发送http请求
在winform里我想发送http请求,并得到返回内容怎么做
比如有个URL为http://localhost:8088/a.aspx?id=2,返回内容为html
我用webbrowser.navigate或webbrowser.url执行,然后得到的webbrowser.documenttext为空,还有其他方法没得
------解决方案--------------------
调用 getPage("http://localhost:8088/a.aspx?id=2");
public void getPage(String url)
{
WebResponse result = null;
try
{
WebRequest req = WebRequest.Create(url);
req.Proxy = null;
result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
//read the stream into a string
StreamReader sr = new StreamReader( ReceiveStream );
string resultstring = sr.ReadToEnd();
Console.WriteLine("\r\nResponse stream received");
Console.WriteLine(resultstring);
}
catch(Exception exp)
{
Console.Write("\r\nRequest failed. Reason:");
Console.WriteLine(exp.Message);
}
finally
{
if ( result != null )
{
result.Close();
}
}
Console.WriteLine("\r\nPress Enter to exit.");
Console.ReadLine();
}