设置Internet Explorer代理在C ++ curl库的要求 - 视窗(Setting t

2019-07-29 06:07发布

嗯,我想用默认的Internet Explorer连接代理设置,以使在C ++卷曲的请求,这是我的示例代码:

CURL *curl;
CURLcode result;

curl = curl_easy_init();

char errorBuffer[CURL_ERROR_SIZE];

if (curl)
{
// Now set up all of the curl options
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt");

// Attempt to retrieve the remote page
result = curl_easy_perform(curl);

// Always cleanup
curl_easy_cleanup(curl);
}

我该怎么做来获取代理服务器的Internet Explorer设置,然后传递给我的卷曲,因此它可以能够使使用代理请求?

提前致谢。

Answer 1:

该WinHttpGetIEProxyConfigForCurrentUser功能获取当前用户的Internet Explorer代理配置。

    #include "stdafx.h" 
#include <Windows.h>
#include <Winhttp.h>
#include <iostream>

using namespace std;
void main() 
{ 
    WINHTTP_CURRENT_USER_IE_PROXY_CONFIG MyProxyConfig;

    if(!WinHttpGetIEProxyConfigForCurrentUser(&MyProxyConfig))
    { 
        //check the error DWORD Err = GetLastError(); 
        DWORD Err = GetLastError(); 
        cout << "WinHttpGetIEProxyConfigForCurrentUser failed with the following error number: " << Err << endl;
        switch (Err) 
       {
            case ERROR_FILE_NOT_FOUND: 
            cout << "The error is ERROR_FILE_NOT_FOUND" << endl; 
            break; 
            case ERROR_WINHTTP_INTERNAL_ERROR:
            cout << "ERROR_WINHTTP_INTERNAL_ERROR" << endl; 
            break; 
            case ERROR_NOT_ENOUGH_MEMORY:
            cout << "ERROR_NOT_ENOUGH_MEMORY" << endl; 
            break; 
            default: cout << "Look up error in header file." << endl; 
        }//end switch 
    }//end if 
    else 
    { 
        //no error so check the proxy settings and free any strings 
        cout << "Auto Detect is: " << MyProxyConfig.fAutoDetect << endl; 

        if(NULL != MyProxyConfig.lpszAutoConfigUrl) 
        { 
            wcout << "AutoConfigURL (MyProxyConfig.lpszAutoConfigUrl) is: " << MyProxyConfig.lpszAutoConfigUrl << endl; 
            GlobalFree(MyProxyConfig.lpszAutoConfigUrl);
        } 
        if(NULL != MyProxyConfig.lpszProxy) 
        { 
            wcout << "AutoConfigURL (MyProxyConfig.lpszProxy) is: " << MyProxyConfig.lpszProxy << endl;
            GlobalFree(MyProxyConfig.lpszProxy);
         }
        if(NULL != MyProxyConfig.lpszProxyBypass) 
        {
             wcout << "AutoConfigURL (is: " << MyProxyConfig.lpszProxyBypass << endl;                      
             GlobalFree(MyProxyConfig.lpszProxyBypass); 
        }
    }//end else 
    cout << "finished!"; 
    system("PAUSE");
}//end main


Answer 2:

你想用InternetQueryOptionINTERNET_OPTION_PROXY ( 文档 )来查找当前代理设置,然后它只是一个问题, 然后将这个代理设置卷曲正常。



Answer 3:

首先,使用windows API来获取代理服务器,然后使用curl_easy_setopt到代理设置为卷曲。

获得代理: WinHttpGetIEProxyConfigForCurrentUser这个API获得代理,但没有WPAD。 如果有人使用“使用自动配置代理”,应该使用WinHttpGetProxyForUrl API来获取proxy.All在MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/aa384096(v=vs 0.85)的.aspx

设置代理: curl_easy_setopt(hCurl, CURLOPT_PROXY, astrProxy.c_str());



文章来源: Setting the Internet Explorer Proxy in cURL Library Requests in C++ - Windows