libcurl的https

zxl2004069 2012-06-05 08:48:38
CURL *curl;

CURLcode res;

curl_global_init(CURL_GLOBAL_ALL);

curl = curl_easy_init();

string m_curPage,m_header;

if(curl){

curl_easy_setopt(curl, CURLOPT_URL, "https://login.vancl.com/Login/Login.aspx");

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1L);

curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);//调试信息打开

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteFunc);

curl_easy_setopt(curl, CURLOPT_WRITEDATA, &m_curPage);

curl_easy_setopt(curl,CURLOPT_HEADERDATA, &m_header);

try

{res = curl_easy_perform(curl);}

catch(...)

{

cout<<GetLastError();

}

cout<<GetLastError();







if(0 != res){

fprintf(stderr,"curl error: %d \n", res);

}

curl_easy_cleanup(curl);

}



红色的url,不同返回的结果不同

Peer certificate cannot be authenticated with given CA certificates



返回超时CURLE_SSL_CONNECT_ERROR



我对https这种不熟悉。

问题1:是不是。每一个访问一个https的网站,都要对方的证书?

问题2:能伪造证书?我只要能获取对方的html代码即可

问题3: 能给个如何使用证书,并提交此证书,发送到https服务器端,并得到HTML代码。

谢谢高手帮助 ,我没有分了。对不起。

...全文
3196 22 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
javaweb_research 2013-08-16
  • 打赏
  • 举报
回复
http://www.softwareace.cn/?p=525
hkcrazyhkcrazy 2012-10-17
  • 打赏
  • 举报
回复
这里我给大家找了个很不错的编译成功的libcurl 支持http https post等等的
大家可以看:http://hi.baidu.com/guhuisec/item/2caa92e081b2872864db006a
hkcrazyhkcrazy 2012-10-10
  • 打赏
  • 举报
回复
求lz发个dll和libcurl,我这个也和你的问题一样!!!我qq:929041889,
Kaile 2012-06-07
  • 打赏
  • 举报
回复
可能是你的curl版本有点问题,可以到 http://curl.haxx.se/ 下载最新7.26
zxl2004069 2012-06-07
  • 打赏
  • 举报
回复
我重新openssl了。
在重新编译了一下libcurl。

好使了。果然是libcurl.lib的问题。
谢谢大家帮助 。。


如果有其它朋友不知道如何编译的libcurl with ssl的,到时留我发信邮件,我会告诉你。
我是编译郁闷了。
zxl2004069 2012-06-07
  • 打赏
  • 举报
回复
我使用的就是7.26的版本。
哭。。你能把你的编译好的lib+dll给我吗?谢谢。

dos 切到d:\curl\lib下面
call "C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
set CFG=release-dll-ssl-dll
set OPENSSL_PATH=d:\openssl
set LIBSSH2_PATH=d:\libssh
set ZLIB_PATH=d:\zlib
nmake -f Makefile.vc10
Kaile 2012-06-06
  • 打赏
  • 举报
回复
这是请求详细信息:

* About to connect() to login.vancl.com port 443 (#0)
* Trying 119.253.51.33...
* connected
* Connected to login.vancl.com (119.253.51.33) port 443 (#0)
* SSL connection using RC4-SHA
* Server certificate:
* subject: C=CN; ST=Beijing; L=Beijing; O=Vancl Chengpin (Beijing) Techno
logy Ltd.; OU=IT dept; OU=Terms of use at www.verisign.com/rpa (c)05; CN=*.vancl
.com
* start date: 2011-12-23 00:00:00 GMT
* expire date: 2013-01-14 23:59:59 GMT
* issuer: C=US; O=VeriSign, Inc.; OU=VeriSign Trust Network; OU=Terms of
use at https://www.verisign.com/rpa (c)10; CN=VeriSign Class 3 Secure Server CA
- G3
* SSL certificate verify result: unable to get local issuer certificate (
20), continuing anyway.
> GET /Login/Login.aspx HTTP/1.1
Host: login.vancl.com
Accept: */*
Accept-Encoding: gzip, deflate
Referer:
Kaile 2012-06-06
  • 打赏
  • 举报
回复
用我写的curl的包装类,访问你提到的网址: https://login.vancl.com/Login/Login.aspx

没遇到问题


Host: login.vancl.com
Accept: */*
Accept-Encoding: gzip, deflate
Referer:

< HTTP/1.1 200 OK
< Cache-Control: private
< Date: Wed, 06 Jun 2012 04:53:59 GMT
< Content-Type: text/html; charset=utf-8
< Server: Microsoft-IIS/6.0
< P3P: CP=CAO PSA OUR
< X-Powered-By: ASP.NET
< X-SERVER: 10.251.21.5
< Set-Cookie: sid=1D8272A742154605967E508F70B29402; domain=.vancl.com; path=/
< Set-Cookie: _vucb=1; domain=vancl.com; path=/
< Set-Cookie: _vuca=42778270F8D14A02825C38EF8CB5014B; domain=vancl.com; expires=
Thu, 06-Jun-2013 04:53:59 GMT; path=/
< Set-Cookie: _vucc=1; domain=vancl.com; expires=Thu, 06-Jun-2013 04:53:59 GMT;
path=/
< Content-Encoding: gzip
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
<
* Connection #0 to host login.vancl.com left intact
zxl2004069 2012-06-06
  • 打赏
  • 举报
回复
访问https://www.cmbchina.com没有问题
* About to connect() to www.cmbchina.com port 443 (#0)
* Trying 218.17.246.162...
* connected
* Connected to www.cmbchina.com (218.17.246.162) port 443 (#0)
* SSL connection using DES-CBC3-SHA
* Server certificate:
* subject: 1.3.6.1.4.1.311.60.2.1.3=CN; businessCategory=V1.0, Clause 5.(
b); serialNumber=4403011228801; C=CN; ST=Guangdong; L=Shenzhen; O=China Merchant
s Bank Co., Ltd; OU=Head Office; OU=Terms of use at www.verisign.com/rpa (c)05;
CN=www.cmbchina.com
* start date: 2010-07-22 00:00:00 GMT
* expire date: 2012-08-20 23:59:59 GMT
* issuer: C=US; O=VeriSign, Inc.; OU=VeriSign Trust Network; OU=Terms of
use at https://www.verisign.com/rpa (c)06; CN=VeriSign Class 3 Extended Validati
on SSL SGC CA
* SSL certificate verify result: unable to get local issuer certificate (
20), continuing anyway.
> GET / HTTP/1.1
Host: www.cmbchina.com
Accept: */*

< HTTP/1.1 200 OK
< Cache-Control: public
< Content-Length: 131282
< Content-Type: text/html; charset=utf-8
< Expires: Wed, 06 Jun 2012 02:55:01 GMT
< Last-Modified: Wed, 06 Jun 2012 02:50:01 GMT
< Server: Microsoft-IIS/6.0
< X-AspNet-Version: 2.0.50727
< X-Powered-By: ASP.NET
< Date: Wed, 06 Jun 2012 02:52:07 GMT
<
* Connection #0 to host www.cmbchina.com left intact
* Closing connection #0


但是访问https://login.vancl.com/Login/Login.aspx地址
出现
* About to connect() to login.vancl.com port 443 (#0)
* Trying 119.253.51.33...
* connected
* Connected to login.vancl.com (119.253.51.33) port 443 (#0)
* Unknown SSL protocol error in connection to login.vancl.com:443
* Closing connection #0
* SSL connect error
curl error: 35
这里会超时,无法访问login.vancl.com


求指点
zxl2004069 2012-06-06
  • 打赏
  • 举报
回复

size_t WriteFunc(char *data, size_t size, size_t nmemb, string *writerData)

{

if (writerData == NULL)

return 0;

size_t len = size*nmemb;

writerData->append(data, len);

return len;

}

int main(void)

{

CURL *curl;

CURLcode res;

curl_global_init(CURL_GLOBAL_ALL);

curl = curl_easy_init();

string m_curPage,m_header;

if(curl){

curl_easy_setopt(curl, CURLOPT_URL, "https://login.vancl.com/Login/Login.aspx");

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteFunc);

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);

curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);//调试信息打开

curl_easy_setopt(curl, CURLOPT_WRITEDATA, &m_curPage);

curl_easy_setopt(curl,CURLOPT_HEADERDATA, &m_header);

try{

res = curl_easy_perform(curl);

}

catch(...)

{

int n = GetLastError();

}

if(0 != res){

fprintf(stderr,"curl error: %d \n", res);

}

curl_easy_cleanup(curl);

}

return 0;

}

就卡住了,求告诉我怎么办。
调试信息如下。

谁能给我代码能用的。100分都给他。
* About to connect() to login.vancl.com port 443 (#0)
* Trying 119.253.51.33... * connected
* Connected to login.vancl.com (119.253.51.33) port 443 (#0)
* Unknown SSL protocol error in connection to login.vancl.com:443
* Closing connection #0
* SSL connect error
curl error: 35
zxl2004069 2012-06-06
  • 打赏
  • 举报
回复
你能把你写的工程文件发一份给我吗?
我的是邮箱是zxl200406@163.com
或我把我的工程文件发给你,你看一下。能行吗?十分感谢
zxl2004069 2012-06-05
  • 打赏
  • 举报
回复
超时返回的是返回超时CURLE_SSL_CONNECT_ERROR
zxl2004069 2012-06-05
  • 打赏
  • 举报
回复
Kaile
改了。是0也不行。你可以试一下。如果不行。我可以把工程发给你。就login.vancl.com/.....不行

https://www.cmbchina.com是要吧的。

Kaile 2012-06-05
  • 打赏
  • 举报
回复
// 校验本地证书,如果不提供,会无法访问SSL站点
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);

// 校验服务器证书,如果过期,或者有其他问题,也不访问
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1L);

这2个选项设为0就好了
qq120848369 2012-06-05
  • 打赏
  • 举报
回复
别了, 我Linux主机现在网络出问题了,没法帮你测, 这种事我都Php几行代码就搞定了。XP我也没编译器。
zxl2004069 2012-06-05
  • 打赏
  • 举报
回复
没有问题,真的。
我可以把工程文件发给你。
qq120848369 2012-06-05
  • 打赏
  • 举报
回复
不是connected了吗,你确定 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteFunc);这个回调函数你写的没问题吗?

qq120848369 2012-06-05
  • 打赏
  • 举报
回复
curl_error()说什么?
zxl2004069 2012-06-05
  • 打赏
  • 举报
回复
* About to connect() to login.vancl.com port 443 (#0)
* Trying 119.253.51.33...
* connected
* Connected to login.vancl.com (119.253.51.33) port 443 (#0)


就这样一直挂着。。超时就返回了。但是并没有数据。我如何改。求高人指点。
zxl2004069 2012-06-05
  • 打赏
  • 举报
回复
楼上的哥们。我代码复制过来的时候没有改。是
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);

但是在访问https://login.vancl.com/Login/Login.aspx是挂起的。你可以试一下。


加载更多回复(2)

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧