c++ - what is the best library to send http request for desktop applications -
my application running in windows , have send requests server. using libcurl.
however there limitation when proxy server authentication involved before request sent out server.
i explored options in libcurl not able make work. if hardcode username / password works. not want user name , password application; prefer libcurl can requests these @ start of transfer.
is there different library can use winhttp or libcurl best 1 use?
below curl settings done before making 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;
i have implemented proxy usages libcurl, possible , cross platform solutions.
having said that, on windows best bet stick windows comm stacks, easier manipulate on windows, , easier work proxies (many times getting config machine definitions automatically.
on windows toss between winhttp , wininet.
- wininet considered easier , more high level, suitable clients access mostly. example popup box asking proxy username , password automatically.
- winhttp considered low level , more suitable complex servers running multithreaded need lot of control on conneciton.
90% of time can use wininet
here complete compare between two: microsoft compare of winhttp , wininet
Comments
Post a Comment