English 中文(简体)
C++-Windows
原标题:Setting the Internet Explorer Proxy in cURL Library Requests in C++ - Windows

我很想利用缺席的因特网探索者联系代理环境,在C++的URL中提出请求,这是我的榜样:

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);
}

我如何检索Proxy互联网探索者环境,然后转往我的URL,以便它能够利用代理人提出请求?

Thanks in advance.

问题回答

WinHttpGetIEProxyConfigForCurrentUser功能检索了现有用户的因特网探索者代理配置。

    #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

您希望使用rel=“nofollow noreferer”>文件,以找到目前的代理环境,然后仅提出一个问题:





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签