赞
踩
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace BMOA.Common.HTTP { public class HttpHelper { /// <summary> /// HttpWebRequest 通过get /// </summary> /// <param name="url">URI</param> /// <returns></returns> public static string GetDataGetHtml(string url) { try { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.Method = "GET"; //对发送的数据不使用缓存 httpWebRequest.AllowWriteStreamBuffering = false; httpWebRequest.Timeout = 300000; httpWebRequest.ServicePoint.Expect100Continue = false; HttpWebResponse webRespon = (HttpWebResponse)httpWebRequest.GetResponse(); Stream webStream = webRespon.GetResponseStream(); if (webStream == null) { return "网络错误(Network error):" + new ArgumentNullException("webStream"); } StreamReader streamReader = new StreamReader(webStream, Encoding.UTF8); string responseContent = streamReader.ReadToEnd(); webRespon.Close(); streamReader.Close(); return responseContent; } catch (Exception ex) { return "网络错误(Network error):" + ex.Message; } } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。