.net 获取https页面的信息 在iis7.5服务器上不管用
让我纠结了一天多的问题,给大家看下,有相同情况的可以不用浪费时间了,本人当时找了好半天都没找到什么有用的信息,项目在本地没有问题,但部署在服务器后,获取不到https页面的信息,加入下面的代码就可以了,因为iis7.5的安全协议比较高的原因。
我的获取页面需要cookie,不需要的可以去掉;
GET的方法:
/// <summary>
/// 获取URL访问的HTML内容 获取https 页面的
/// </summary>
/// <param name="Url">URL地址</param>
/// <returns>HTML内容</returns>
public static string GetWebContent(string Url, CookieContainer cookieContainer)
{
string strResult = "";
try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.CookieContainer = cookieContainer;
request.Timeout = ;
request.Headers.Set("Pragma", "no-cache"); HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream(); Encoding encoding = Encoding.GetEncoding("utf-8");
StreamReader streamReader = new StreamReader(streamReceive, encoding);
strResult = streamReader.ReadToEnd();
}
catch
{ }
return strResult;
}
POST的方法:
/// <summary>
/// post提交数据到https
/// </summary>
/// <param name="posturl"></param>
/// <param name="postdata"></param>
/// <param name="header"></param>
/// <param name="cookieContainer"></param>
/// <returns></returns>
public static string SetPostHtml(string posturl, string postdata, HttpHeader header, CookieContainer cookieContainer)
{
string restr = "";
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
HttpWebRequest request = null;
HttpWebResponse response = null;
request = (HttpWebRequest)WebRequest.Create(posturl);
request.CookieContainer = cookieContainer;
request.Method = header.method;
request.Referer = header.Referer;
request.ContentType = header.contentType;
byte[] postdatabyte = Encoding.UTF8.GetBytes(postdata);
request.ContentLength = postdatabyte.Length;
request.AllowAutoRedirect = false;
request.KeepAlive = true;
//提交请求
Stream stream;
stream = request.GetRequestStream();
stream.Write(postdatabyte, , postdatabyte.Length);
stream.Close();
//接收响应
response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
restr = reader.ReadToEnd().ToString();
}
return restr;
}
希望对大家有帮助;
.net 获取https页面的信息 在iis7.5服务器上不管用的更多相关文章
- 关于wcf异常异常信息:由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults (从 ServiceBehaviorAttribut
异常信息:由于内部错误,服务器无法处理该请求.有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults (从 ServiceBehaviorAttribut ...
- 获取当前页面URL信息
文章链接:http://www.cnblogs.com/hongmaju/p/5510988.html 查看信息可以在控制台输出(tab或者右移补全): 如:document.URL window. ...
- js获取当前页面url信息
<html> <head> <meta charset="utf-8" /> <title></title> <s ...
- js获取当前页面url信息方法(JS获取当前网址信息)
设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或 ...
- 异常信息:由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults
有方法说找到web.config 文件修改如下(蓝色部分) <behaviors> <serviceBehaviors> <behavior> ...
- 由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults (从 ServiceBehaviorAttribute 或从 <serviceDebug> 配置行为)以便将异常信息发送回客户端,或打开对每个 Microsoft .NET Framework SDK 文档的跟踪并检查服务器跟踪日志。
客户端调用WCF的时候报上面的错误,WCF只能序列化基础的数据类型,不能直接序列化SqlParameter类型,需要使用自定义类,然后在WCF服务端转换的方式解决: 自定义类代码如下: using S ...
- PHP获取客户端请求头信息
获取HTTP请求头信息 Apache 如果web服务器用的是apache,可以直接用php的库函数getallheaders() Nginx 如果web服务器用的是nginx,则无法直接使用getal ...
- 利用PHP获取访客IP、地区位置、浏览器及来源页面等信息
这篇文章主要介绍了利用PHP获取访客IP.地区位置.浏览器及来源页面等信息的相关资料,文中给出了详细的示例代码供大家参考学习,对大家具有一定的参考借鉴价值,需要的朋友们下面来一起看看吧. 前言 本文中 ...
- js获取当前页面url网址信息
js如何准确获取当前页面url网址信息 在WEB开发中,时常会用到javascript来获取当前页面的url网址信息,在这里是我的一些获取url信息的小总结. 下面我们举例一个URL,然后获得它的各个 ...
随机推荐
- JavaScript与DOM
文档对象模型Document Object Model DOM(Document Object Model,文档对象模型)是一个通过和JavaScript进行内容交互的API.Javascript和D ...
- android 弹出的软键盘遮挡住EditText文本框的解决方案
1.android 弹出的软键盘遮挡住EditText文本框的解决方案: 把Activit对应的布局文件filename.xml文件里的控件用比重设置布局.(例如:android:layout_wei ...
- Vim编辑器运用的五个技巧
导读 如今 Vim 是每个人最喜欢的 Linux 文本编辑器,也是开发者和系统管理者最喜爱的开源工具.大多数人只是熟悉Vim的最最基本的操作,只能在终端使用 Vim 修改文本,但是它并没有任何一个我想 ...
- Distinct Subsequences Leetcode
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- 试用vSphere 6(三):安装vCenter 6(独立数据库)之:vCenter安装与配置
------------------------------------------ 一.VMware vSphere 6(RC版)安装配置系列文章: 1.试用vSphere 6(一):安装ESXi ...
- linux文件远程传输客户端shell脚本与分布式客户机时间同步脚本
#!/bin/bash # 将代码和脚本传送至worker节点 # 改变当前工作目录 cd ${AMAZONCRAWLER_HOME} #读取worker节点ip列表 i= while read li ...
- django ATOMIC_REQUESTS
在数据库配置中,如果配置了此属性为True,如下: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.xxx', 'NAME': '', ...
- python gui之tkinter界面设计pythonic设计
ui的设计,控件id的记录是一件比较繁琐的事情. 此外,赋值和读取数据也比较繁琐,非常不pythonic. 有没有神马办法优雅一点呢?life is short. 鉴于控件有name属性,通过dir( ...
- Glyphicons字体图标
Glyphicons字体图标-----好处可以减少请求,容易控制样式! <p> <button type="button" class="btn btn ...
- PHPCMS V9教程之快速入门
这篇文章要为大家来介绍PHPCMS V9这个系统的一些基本知识,PHPCMS是基于面向对象的,严格的安装MVC开发模式开发的CMS系统,同时他还是一个非 常不错的PHP框架.下面我们一起看一下PHPC ...