OpenReadWithHttps
2014-09-25 15:18
204 查看
///<summary>
///采用https协议访问网络
///</summary>
///<param name="URL">url地址</param>
///<param name="strPostdata">发送的数据</param>
///<returns></returns>
public string OpenReadWithHttps(string URL, string strPostdata)
{
Encoding encoding = Encoding.Default;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "post";
request.Accept = "text/html, application/xhtml+xml, */*";
request.ContentType = "application/x-www-form-urlencoded";
CookieContainer objcok = new CookieContainer();
objcok.Add(new Uri("http://sufei.cnblogs.com"), new Cookie("键", "值"));
objcok.Add(new Uri("http://sufei.cnblogs.com"), new Cookie("键", "值"));
objcok.Add(new Uri("http://sufei.cnblogs.com"), new Cookie("sidi_sessionid", "360A748941D055BEE8C960168C3D4233"));
request.CookieContainer = objcok;
byte[] buffer = encoding.GetBytes(strPostdata);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8"));
return reader.ReadToEnd();
}
///采用https协议访问网络
///</summary>
///<param name="URL">url地址</param>
///<param name="strPostdata">发送的数据</param>
///<returns></returns>
public string OpenReadWithHttps(string URL, string strPostdata)
{
Encoding encoding = Encoding.Default;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "post";
request.Accept = "text/html, application/xhtml+xml, */*";
request.ContentType = "application/x-www-form-urlencoded";
CookieContainer objcok = new CookieContainer();
objcok.Add(new Uri("http://sufei.cnblogs.com"), new Cookie("键", "值"));
objcok.Add(new Uri("http://sufei.cnblogs.com"), new Cookie("键", "值"));
objcok.Add(new Uri("http://sufei.cnblogs.com"), new Cookie("sidi_sessionid", "360A748941D055BEE8C960168C3D4233"));
request.CookieContainer = objcok;
byte[] buffer = encoding.GetBytes(strPostdata);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8"));
return reader.ReadToEnd();
}
相关文章推荐
- https://blog.hanschen.org/2012/10/17/open-application-launcher-with-super-key/
- 加载图片莫名变成黑色 ImageIO: CGImageReadCreateDataWithMappedFile 'open' failed '
- Java Read CSV File In Java With OpenCSV library 以及中文件乱码解决, Mapping CSV with Java beans
- 图片操作异常 ImageIO: CGImageReadCreateDataWithMappedFile 'open' failed
- Java Read CSV File In Java With OpenCSV library, int filed 属性为 int类型
- IOS 图片下载成功,展示却灰灰的问题。ImageIO: CGImageReadCreateDataWithMappedFile 'open' failed
- 如何使用沙箱测试单笔转账到支付宝账号(php版) https://openclub.alipay.com/read.php?tid=1770&fid=28
- open text file with notpad from c# code
- NIOSII Slave with readdatavalid signal must support at least 1 pending read 解决方法。
- Possible problem with readdir() and/or lstat()
- Read the sheets in the Excel with QT
- sql With(NoLock),With(ReadPast)
- Paraglyph_-_Open_Source_Development_with_CVS__3rd_Edition
- linux open read write lseek close
- https://github.com/Trinea/android-open-project
- Curl POST to HTTPS url gives SSLRead() error:curl: (56) SSLRead() return error -9806
- With Visual Studio, Open Same File In Two Windows, Updates Reflected in Both
- GPG key retrieval failed: [Errno 14] Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
- linux文件操作函数(open、write、read、close)可用于串口读写
- Resolved validation conflict with readonly