My application is running in Windows and I have to send some requests to the server. I am currently using libcurl.
However there is a limitation when proxy server with authentication is involved before the request sent out to the server.
I explored the options in libcurl but i could not able to make it work. If i hardcode the username / password it works. But I do not want to get the user name and password by my application; I would prefer that libcurl can requests these at the start of a transfer.
Is there a different library i can use like winhttp or libcurl is the best one to use?
Below are the curl settings done before making the request
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_URL, urlString.data());
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, receiveDataCallback);
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &curlPerformStorage);
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_FOLLOWLOCATION, 1);
if(NULL != GetWindowsProxyConfig().lpszProxy){
LPWSTR wStr = GetWindowsProxyConfig().lpszProxy;
char* buffer = new char[100];
wcstombs(buffer, wStr, 100) ;
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_PROXY, "<proxy_name>");
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_PROXYPORT, <number>);
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_NONE);
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
} else {
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_PROXY, "<proxy_name>");
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_PROXYPORT, <number>);
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
}
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_USE_SSL, CURLUSESSL_ALL);
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_SSL_VERIFYPEER, 1);
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_SSL_VERIFYHOST, 2);
if(proxyStr.length() > 0){
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_HTTPPROXYTUNNEL, 1L);
}
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_FAILONERROR, 1);
curlResultCode= curl_easy_setopt ( curlHandle, CURLOPT_ERRORBUFFER, errorbuffer );
int nConnectionTimeout = curlPerformStorage.GetConnectionTimeOut();
if (nConnectionTimeout > 0)
{
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_CONNECTTIMEOUT, nConnectionTimeout);
}
int nTransferTimeout = curlPerformStorage.GetTransferTimeOut();
if (nTransferTimeout > 0)
{
curlResultCode=curl_easy_setopt(curlHandle, CURLOPT_TIMEOUT, nTransferTimeout);
}
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_PROGRESSFUNCTION , ProgressCallback);
if (curlResultCode == CURLE_OK)
{
curlResultCode = curl_easy_setopt(curlHandle, CURLOPT_NOPROGRESS, FALSE);
curlResultCode= curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA , &curlPerformStorage);
}
curlResultCode = curl_easy_perform(curlHandle);
if (curlResultCode != CURLE_OK)
{
}
else
{
}
curl_easy_reset(curlHandle);
return curlResultCode;