在C++; 我尝试用C++中的LIbCURL创建HTTP GET请求。首先我使用这个代码(没有代理,它工作) #包括 #包括 #包括 内部主(空) { 卷曲*卷曲; 卷曲编码; curl=curl_easy_init(); if(curl){ curl\u easy\u setopt(curl,CURLOPT\u URL,“https://stackoverflow.com/"); /*执行请求,res将获得返回代码*/ res=旋度(curl)\u容易执行(curl); /*总是清理*/ 旋度\轻松\清洁(旋度); } 返回0; }

在C++; 我尝试用C++中的LIbCURL创建HTTP GET请求。首先我使用这个代码(没有代理,它工作) #包括 #包括 #包括 内部主(空) { 卷曲*卷曲; 卷曲编码; curl=curl_easy_init(); if(curl){ curl\u easy\u setopt(curl,CURLOPT\u URL,“https://stackoverflow.com/"); /*执行请求,res将获得返回代码*/ res=旋度(curl)\u容易执行(curl); /*总是清理*/ 旋度\轻松\清洁(旋度); } 返回0; },c++,libcurl,C++,Libcurl,第二,我尝试使用带有用户名和密码的代理身份验证,但没有得到任何响应 #include <stdio.h> #include <curl/curl.h> #include <iostream> int main(void) { CURL* curl; CURLcode res; curl = curl_easy_init(); if (curl) {

第二,我尝试使用带有用户名和密码的代理身份验证,但没有得到任何响应

#include <stdio.h>
#include <curl/curl.h>
#include <iostream>

    int main(void)
    {
    
       CURL* curl;
        CURLcode res;
    
        curl = curl_easy_init();
        if (curl) {
         
            curl_easy_setopt(curl, CURLOPT_URL, "https://stackoverflow.com/");
            curl_easy_setopt(curl, CURLOPT_PROXY, "here is my proxy");
            curl_easy_setopt(curl, CURLOPT_USERNAME, "my username");
            curl_easy_setopt(curl, CURLOPT_PASSWORD, "my pass");
    
            /* Perform the request, res will get the return code */
            res = curl_easy_perform(curl);
    
            /* always cleanup */
            curl_easy_cleanup(curl);
        }
        return 0;
    }
#包括
#包括
#包括
内部主(空)
{
卷曲*卷曲;
卷曲编码;
curl=curl_easy_init();
if(curl){
curl\u easy\u setopt(curl,CURLOPT\u URL,“https://stackoverflow.com/");
curl_easy_setopt(curl,CURLOPT_PROXY,“这是我的代理”);
curl_easy_setopt(curl,CURLOPT_用户名,“我的用户名”);
curl_easy_setopt(curl,CURLOPT_密码,“我的通行证”);
/*执行请求,res将获得返回代码*/
res=旋度(curl)\u容易执行(curl);
/*总是清理*/
旋度\轻松\清洁(旋度);
}
返回0;
}
我不知道为什么它不起作用。 代理在c#中进行了测试,它可以工作

找到答案只需将CURLOPT_用户名替换为CURLOPT_PROXYUSERNAME即可 以及CURLOPT_密码和CURLOPT_代理密码。 工作代码

#include <stdio.h>
#include <curl/curl.h>
#include <iostream>

int main(void)
{

    CURL* curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://stackoverflow.com/");
        curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:port");
        curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME, "username");
        curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD, "password");
       curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
}
#包括
#包括
#包括
内部主(空)
{
CURL*CURL=CURL_easy_init();
if(curl){
curl\u easy\u setopt(curl,CURLOPT\u URL,“https://stackoverflow.com/");
curl\u easy\u setopt(curl,CURLOPT\u PROXY,“http://proxy:port");
curl_easy_setopt(curl,CURLOPT_PROXYUSERNAME,“用户名”);
curl_easy_setopt(curl,CURLOPT_PROXYPASSWORD,“密码”);
旋度,易于执行(旋度);
旋度\轻松\清洁(旋度);
}
}
找到答案只需将CURLOPT_用户名替换为CURLOPT_代理用户名 以及CURLOPT_密码和CURLOPT_代理密码。 工作代码

#include <stdio.h>
#include <curl/curl.h>
#include <iostream>

int main(void)
{

    CURL* curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://stackoverflow.com/");
        curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:port");
        curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME, "username");
        curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD, "password");
       curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
}
#包括
#包括
#包括
内部主(空)
{
CURL*CURL=CURL_easy_init();
if(curl){
curl\u easy\u setopt(curl,CURLOPT\u URL,“https://stackoverflow.com/");
curl\u easy\u setopt(curl,CURLOPT\u PROXY,“http://proxy:port");
curl_easy_setopt(curl,CURLOPT_PROXYUSERNAME,“用户名”);
curl_easy_setopt(curl,CURLOPT_PROXYPASSWORD,“密码”);
旋度,易于执行(旋度);
旋度\轻松\清洁(旋度);
}
}