通过 cURL returns 407 使用 NTLM 进行代理身份验证,即使具有适当的凭据

Proxy authentiacation with NTLM via cURL returns 407 even with proper credentials

我正在尝试使用使用 NTLM 身份验证的代理访问服务器。 问题是,即使我提供了正确的凭据(我已经用 Firefox 测试了它们并且代理、端口、用户名和密码都是正确的),我也会收到 407(代理需要身份验证)。

我试过使用 CURLAUTH_NTLM、CURLAUTH_NTLM 和两者的逻辑组合,但仍然没有。

我使用的是最新版本的 cURL (7.42.1) 和最新版本的 openSSL (1.0.2)。

谁能告诉我我做错了什么?

这是我的 C/C+++ 代码:

int _main()
{
    CURL *hCurl;    
    CURLcode curlCode;

    char username[] = "domain\user";
    char password[] = "pass";
    char proxy[] = "myproxy:8080";
    char url[] = "http://some_random_url.com";

    hCurl = curl_easy_init();
    if(hCurl) 
    {
        curl_easy_setopt(hCurl, CURLOPT_URL, url);

        curlCode = curl_easy_setopt(hCurl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
        curlCode = curl_easy_setopt(hCurl, CURLOPT_PROXY, proxy);
        curlCode = curl_easy_setopt(hCurl, CURLOPT_HTTPAUTH,  /*CURLAUTH_BASIC | */CURLAUTH_NTLM);
        curlCode = curl_easy_setopt(hCurl, CURLOPT_PROXYUSERNAME, username);
        curlCode = curl_easy_setopt(hCurl, CURLOPT_PROXYPASSWORD, password);

        while(true)
        {
            curlCode = curl_easy_perform(hCurl);
            /* Check for errors */ 
            if(curlCode != CURLE_OK)
                fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(curlCode));

            Sleep(3000);
        }

        curl_easy_cleanup(hCurl);
    }

    getchar();
    return 0;

}

阅读文档。 CURLOPT_HTTPAUTH 设置用于远程 HTTP 服务器而非代理的凭据:

Pass a long as parameter, which is set to a bitmask, to tell libcurl which authentication method(s) you want it to use speaking to the remote server.

... Set the actual name and password with the CURLOPT_USERPWD option or with the CURLOPT_USERNAME and the CURLOPT_PASSWORD options.

...

For authentication with a proxy, see CURLOPT_PROXYAUTH.

使用 CURLOPT_PROXYAUTH 指定代理身份验证方法 (NTLM),并使用 CURLOPT_PROXYUSERPWD 设置代理凭据。