I'm trying to access a server using a proxy that uses NTLM authentication. The problem is that even if I give the correct credentials (I've tested them with Firefox and the proxy, port, username and password are correct) I receive 407 (proxy requires authentication).
I've tried using CURLAUTH_NTLM, CURLAUTH_NTLM and a logical combination of both and still nothing.
I've using the latest version of cURL (7.42.1) and the latest version of openSSL (1.0.2).
Can anyone please tell me what I'm doing wrong?
This is my C/C+++ code:
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;
}
Read the documentation. CURLOPT_HTTPAUTH
sets the credentials used for the remote HTTP server, not the proxy:
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
.
Use CURLOPT_PROXYAUTH
to specify the proxy authentication method (NTLM), and use CURLOPT_PROXYUSERPWD
to set the proxy credentials.