如何发送连接请求至https服务器,并向其发送数据

updarren 2011-09-28 10:38:53
我现在需要连接一个HTTPS服务器https://221.176.1.140:443/do_login.php,直接把账号写到POST到/do_login.php。HttpSendRequest的时候,总是不成功,返回值是 “Cannot perform http request code: 12057”

bool CSslConnection::ConnectToHttpsServer(string &strVerb)
{
try {
m_hInternet = InternetOpen(m_strAgentName.c_str(), INTERNET_OPEN_TYPE_PRECONFIG ,
NULL, NULL, 0);
if (!m_hInternet) {
m_strLastError = "Cannot open internet";
m_lastErrorCode = GetLastError();
return false;
}

m_hSession = InternetConnect(m_hInternet,
m_strServerName.c_str(),
m_wPort,
m_strUserName.c_str(),
m_strPassword.c_str(),
INTERNET_SERVICE_HTTP,
0,
0);
if (!m_hSession) {
m_strLastError = "Cannot connect to internet";
m_lastErrorCode = GetLastError();
ClearHandles();
return false;
}
m_hRequest = HttpOpenRequest(m_hSession,
strVerb.c_str(),
m_strObjectName.c_str(),
NULL,
"",
NULL,
m_secureFlags,
m_ReqID);
if (!m_hRequest) {
m_strLastError = "Cannot perform http request";
m_lastErrorCode = GetLastError();
ClearHandles();
return false;
}

m_ReqID++;
}
catch(...) {
m_strLastError = "Memory Exception occured";
m_lastErrorCode = GetLastError();
return false;
}
return true;
}

bool CSslConnection::SendHttpsRequest()
{
try {
for (int tries = 0; tries < 20; ++tries) {
// int result = HttpSendRequest(m_hRequest, NULL, 0, NULL, 0);
int result = HttpSendRequest(m_hRequest, NULL, -1L, NULL, 0); //2011-09-28 -1L
if (result)
return true;
int lastErr = GetLastError();
if (lastErr == ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED) {
if (!SetClientCert()) {
m_strLastError = "Cannot perform http request, client authentication needed but couldnt detect required client certificate";
m_lastErrorCode = GetLastError();
return false;
}
}
else if (lastErr == ERROR_INTERNET_INVALID_CA) {
m_strLastError = "Cannot perform http request, client authentication needed, invalid client certificate is used";
m_lastErrorCode = GetLastError();
return false;
}
else {
m_strLastError = "Cannot perform http request";
m_lastErrorCode = GetLastError();
return false;
}
}
}
catch(...) {
m_strLastError = "Memory Exception occured";
m_lastErrorCode = GetLastError();
return false;
}
return false;
}
...全文
643 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
updarren 2011-09-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 oyljerry 的回复:]

HttpSendRequest return error code(12057, ERROR_INTERNET_SEC_CERT_REV_FAILED,means Revocation of the SSL certificate failed)

认证信息等可能有问题.
[/Quote]

那可能是我证书没安装成功吗。。。
向立天 2011-09-28
  • 打赏
  • 举报
回复
直接用openurl试试呢
oyljerry 2011-09-28
  • 打赏
  • 举报
回复
HttpSendRequest return error code(12057, ERROR_INTERNET_SEC_CERT_REV_FAILED,means Revocation of the SSL certificate failed)

认证信息等可能有问题.
updarren 2011-09-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 masterz 的回复:]

boost.asio has an example of SSL client - doc/html/boost_asio/example/ssl/client.cpp
[/Quote]

谢谢你!

可是这个我看不懂, 我是个c++初学者。。。调用HttpSendRequest 返回的error code: 12057是什么,msdn的里面没讲清楚
masterz 2011-09-28
  • 打赏
  • 举报
回复
boost.asio has an example of SSL client - doc/html/boost_asio/example/ssl/client.cpp

18,363

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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