使用libcurl和ntml时出现错误http 407
Error http 407 using libcurl and ntml
我正在开发一个小型应用程序。为了测试目的,我试图在ntlm代理后面使用libcurl"ping"谷歌。这是我的c++代码:
CURLcode testConnection(void)
{
CURL *curl;
CURLcode res = CURLE_OK;
res = curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl)
{
cout << "Url: " << curl_easy_strerror(curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com")) << "n";
cout << "T-out: " << curl_easy_strerror(curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3)) << "n";
cout << "No_body: " << curl_easy_strerror(curl_easy_setopt(curl, CURLOPT_NOBODY, true)) << "n";
cout << "Proxy Url: " << curl_easy_strerror(curl_easy_setopt(curl, CURLOPT_PROXY, "proxyrm.wind.root.it")) << "n";
cout << "Proxy Port: " << curl_easy_strerror(curl_easy_setopt(curl, CURLOPT_PROXYPORT, 8080)) << "n";
cout << "Ntml: " << curl_easy_strerror(curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM)) << "n";
cout << "Verbose: " << curl_easy_strerror(curl_easy_setopt(curl, CURLOPT_VERBOSE, true)) << "n";
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
else
res = CURLE_FAILED_INIT;
curl_global_cleanup();
return res;
}
所有这些都很好,因为详细的输出如下。
Url: No error
T-out: No error
No_body: No error
Proxy Url: No error
Proxy Port: No error
Ntml: No error
Verbose: No error
* About to connect() to proxy myroxy port 8080 (#0)
* Trying IP...
* Connected to myroxy (IP) port 8080 (#0)
> HEAD http://www.google.com HTTP/1.1
Host: www.google.com
Accept: */*
Proxy-Connection: Keep-Alive
< HTTP/1.1 407 Proxy Authentication Required
< Proxy-Authenticate: NTLM
< Proxy-Authenticate: BASIC realm="windroot"
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Type: text/html; charset=utf-8
* HTTP/1.1 proxy connection set close!
< Proxy-Connection: close
< Set-Cookie: BCSI-CS-602d36a7505d346e=2; Path=/
< Connection: close
< Content-Length: 989
<
* Closing connection 0
Curl Final: No error
但是,如果我尝试pinghttps://google.com结果变成这个
Url: No error
T-out: No error
No_body: No error
Proxy Url: No error
Proxy Port: No error
Ntml: No error
Ntml: No error
Ntml: No error
Verbose: No error
* About to connect() to proxy myroxy port 8080 (#0
* Trying IP...
* Connected to myroxy (IP) port 8080 (#0)
* Establish HTTP proxy tunnel to www.google.com:443
> CONNECT www.google.com:443 HTTP/1.1
Host: www.google.com:443
Proxy-Connection: Keep-Alive
< HTTP/1.1 407 Proxy Authentication Required
< Proxy-Authenticate: NTLM
< Proxy-Authenticate: BASIC realm="windroot"
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Type: text/html; charset=utf-8
< Proxy-Connection: close
< Set-Cookie: BCSI-CS-602d36a7505d346e=2; Path=/
< Connection: close
< Content-Length: 1135
<
* Ignore 1135 bytes of response-body
* Received HTTP code 407 from proxy after CONNECT
* Connection #0 to host myroxy left intact
Curl Final: Failure when receiving data from the peer
在命令行中使用curl可以ping https(我必须指定-k参数),但我不知道这是否真的相关。有人能帮我弄清楚发生了什么?如何避免这种情况?
已解决:我缺少此指令
curl_easy_setopt(ctx, CURLOPT_PROXYUSERPWD, ":");
这(我认为)告诉curl使用从SO检索到的用户名和密码,通过ntlm auth
相关文章:
- 带有边界获取错误的 HTTP POST
- 为什么这C++ASIO,当执行HTTP / SSL请求时,BEAST服务器会进入错误状态
- 使用 C++ 套接字发出 HTTP GET 请求时出现 301 错误
- VS2015 中卡萨布兰卡的链接器错误,同时尝试构建一个简单的 HTTP 侦听器
- 如何修复 c++ 提升 http 示例中的"找不到架构x86_64符号"错误
- 使用 winsock 库发送 GET HTTP 请求时出现 400 错误请求错误
- 我一直在使用C 的HTTP/1.0 400 JSON RPC错误
- c++ Http 请求 SSL 错误
- 使用libcurl和ntml时出现错误http 407
- PHP7 和 IIS8 HTTP 错误 500.0 - FastCGI 进程意外退出
- HTTP 400 错误请求
- FCGI 进程在 HTTP 502 错误后被终止
- 通过 tcp 和浏览器发送带有 HTTP 协议的 html 文件会显示错误
- 错误C2668从站点对重载函数代码的调用不明确http://h264bitstream.sourceforge.net/
- 使用HTTP上载文件.获取错误:-HttpSendReuest 12005
- 通过代理发出请求时出现HTTP错误
- Qt http在谷歌上的错误请求
- HTTP/1.1 401使用GSOAP调用EWS时出现未经授权的错误
- 发送http post消息错误报告的安全方式
- 链接器错误LNK2019在boost asio http客户端代码