C# Get请求数据 WebClient和HttpWebRequest获取HTML代码 蓝色梦想网
2012-06-13 13:44
861 查看
#region C# Get请求数据
/// <summary>
/// C# Get请求数据
/// </summary>
/// <param name="url">请求的URL地址</param>
/// <returns></returns>
private static string GetResult(string url)
{
WebClient wc = new WebClient();
string s = wc.DownloadString(url);
s = HttpUtility.UrlDecode(s);
return s;
}
/// <summary>
/// 可返回WEB请求出错请求信息的GET方法
/// </summary>
/// <param name="url">请求的URL</param>
/// <returns></returns>
private static string GetResultByHttpWebRequst(string url)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.UserAgent = "MSIE6.0";
req.Method = "GET";
HttpWebResponse res;
try { res = (HttpWebResponse)req.GetResponse(); }
catch (WebException ex) { res = (HttpWebResponse)ex.Response; }
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
string bstr = sr.ReadToEnd();
return bstr;
}
#endregion
推荐阅读:蓝色梦想网
/// <summary>
/// C# Get请求数据
/// </summary>
/// <param name="url">请求的URL地址</param>
/// <returns></returns>
private static string GetResult(string url)
{
WebClient wc = new WebClient();
string s = wc.DownloadString(url);
s = HttpUtility.UrlDecode(s);
return s;
}
/// <summary>
/// 可返回WEB请求出错请求信息的GET方法
/// </summary>
/// <param name="url">请求的URL</param>
/// <returns></returns>
private static string GetResultByHttpWebRequst(string url)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.UserAgent = "MSIE6.0";
req.Method = "GET";
HttpWebResponse res;
try { res = (HttpWebResponse)req.GetResponse(); }
catch (WebException ex) { res = (HttpWebResponse)ex.Response; }
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
string bstr = sr.ReadToEnd();
return bstr;
}
#endregion
推荐阅读:蓝色梦想网
相关文章推荐
- WebClient HttpWebRequest从网页中获取请求数据
- C# Get请求数据 WebClient和HttpWebRequest获取HTML代码
- js_html_input中autocomplete="off"在chrom中失效的解决办法 使用JS模拟锚点跳转 js如何获取url参数 C#模拟httpwebrequest请求_向服务器模拟cookie发送 实习期学到的技术(一) LinqPad的变量比较功能 ASP.NET EF 使用LinqPad 快速学习Linq
- HttpWebRequest post请求获取webservice void数据信息
- WebClient和WebRequest获取html代码
- 使用WebClient或HttpWebRequest模拟上传文件和数据
- 取远程网页数据 WebClient,HttpWebRequest
- HttpWebRequest POST 数据时请求头多了一行Expect: 100-continue,少了数据行
- silverlight HttpWebRequest post请求数据
- j2ee的web项目,在浏览器中发起一个该项目中html页面的绝对地址,也是发起的一个http url请求,请求的响应报文的结果就是该html页面的所有html代码
- HttpWebRequest 下载网页Html代码 下载文件(Remote和FTP)Get方式
- Ajax核心XMLHttpRequest对象、(发送请求、接收)方法和属性介绍、AJAX开发框架、数据格式提要(XML、JSON、HTML)
- C#如何HttpWebRequest模拟登陆,获取服务端返回Cookie以便登录请求后使用
- C#POST数据,HttpWebRequest请求页面,HttpWebResponse返回数据
- 【JavaWeb-6】HttpServletResponse的字符字节输出流、编码、文件下载、Captcha图片与HttpServletRequest获取request数据表单非表单数据、重定向与转发
- 使用WebClient HttpWebRequest 的高级应用,获取带验证的session下载权限
- C#网页采集数据的几种方式(WebClient、WebBrowser和HttpWebRequest/HttpWebResponse)
- 使用WebClient或HttpWebRequest模拟上传文件和数据
- Ajax核心XMLHttpRequest对象、(发送请求、接收)方法和属性介绍、AJAX开发框架、数据格式提要(XML、JSON、HTML)
- Android 网络:使用URLConnection提交请求,获取html代码加载WebView