http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 4796|回复: 7

[HttpHelper] GET Https Api接口报错

[复制链接]
发表于 2018-4-26 20:22:31 | 显示全部楼层 |阅读模式
访问https的api接口,用开发助手就能获取到返回的数据,根据开发助手生成代码就会出现The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
具体图片与代码如下

QQ图片20180426201920.jpg

HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
    URL = "https://10.8.17.18:8443/api/v1/coSpaces",//URL     必需项
    Method = "GET",//URL     可选项 默认为Get
    SecurityProtocol = SecurityProtocolType.Tls12,//当出现“请求被中止: 未能创建 SSL/TLS 安全通道”时需要配置此属性
    Timeout = 100000,//连接超时时间     可选项默认为100000
    ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000
    IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
    Cookie = "",//字符串Cookie     可选项
    UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",//用户的浏览器类型,版本,操作系统     可选项有默认值
    Accept = "text/html, application/xhtml+xml, */*",//    可选项有默认值
    ContentType = "text/html",//返回类型    可选项有默认值
    Referer ="",//来源URL     可选项
    Allowautoredirect = False,//是否根据301跳转     可选项
    AutoRedirectCookie = False,//是否自动处理Cookie     可选项
    //CerPath = "d:\123.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数
    //Connectionlimit = 1024,//最大连接数     可选项 默认为1024
    Postdata = "",//Post数据     可选项GET时不需要写
    //ProxyIp = "192.168.1.105:2020",//代理服务器ID     可选项 不需要代理 时可以不设置这三个参数
    //ProxyPwd = "123456",//代理服务器密码     可选项
    //ProxyUserName = "administrator",//代理服务器账户名     可选项
    ResultType = ResultType.String,//返回数据类型,是Byte还是String
};
item.Header.Add("Authorization", "Basic YWRtaW46eWZkQDIwMTgwNA==");//设置请求头信息(Header)
HttpResult result = http.GetHtml(item);
string html = result.Html;
string cookie = result.Cookie;




1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2018-4-26 20:47:44 | 显示全部楼层
便少配置一些个ssl属性
发表于 2018-4-26 20:49:33 | 显示全部楼层
 楼主| 发表于 2018-4-27 10:21:57 | 显示全部楼层
sufeinet 发表于 2018-4-26 20:49
http://www.sufeinet.com/thread-17747-1-1.html

WebHeaderCollection header = new WebHeaderCollection();
            string auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(this.textBox2.Text + ":" + this.textBox3.Text));
            header.Add("Authorization", "Basic " + auth);

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            CsharpHttpHelper.HttpHelper http = new CsharpHttpHelper.HttpHelper();
            CsharpHttpHelper.HttpItem item = new CsharpHttpHelper.HttpItem()
            {
                URL = this.textBox1.Text,
                Method = "GET",
                ResultType = ResultType.String,//返回数据类型,是Byte还是String
                Header = header,
            };
            CsharpHttpHelper.HttpResult result = http.GetHtml(item);
            string html = result.Html;
            string cookie = result.Cookie;


按你之前的帖子加上了ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;还是提示The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel。
 楼主| 发表于 2018-4-27 10:25:46 | 显示全部楼层
sufeinet 发表于 2018-4-26 20:49
http://www.sufeinet.com/thread-17747-1-1.html

有一点我搞不懂,用开发助手就没有问题,开发助手生成的代码就有问题,为啥嘞
发表于 2018-4-27 11:47:05 | 显示全部楼层
chinadevil 发表于 2018-4-27 10:25
有一点我搞不懂,用开发助手就没有问题,开发助手生成的代码就有问题,为啥嘞

这个应该是生成的代码有些地方不太一样。我看你是终身会员,可以下载源码看看
 楼主| 发表于 2018-4-27 12:23:09 | 显示全部楼层
sufeinet 发表于 2018-4-27 11:47
这个应该是生成的代码有些地方不太一样。我看你是终身会员,可以下载源码看看

找到原因了,是我用的HttpHelper.dll和你的HttpHelper.dll版本不一样,不过遇到新的问题了,winform没有问题,webform有同样的问题
发表于 2018-4-28 07:55:07 | 显示全部楼层
chinadevil 发表于 2018-4-27 12:23
找到原因了,是我用的HttpHelper.dll和你的HttpHelper.dll版本不一样,不过遇到新的问题了,winform没有 ...

是引用的同样的Dll吗,报的什么错,也是上面的吗
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-18 17:01

© 2014-2021

快速回复 返回顶部 返回列表