Request Example Code

Using HTTP/Socks5 Proxy in C++ (with Username and Password)

HTTP Proxy + Username and Password (Complete Example)

#include <curl/curl.h>
#include <iostream>
static size_t write_cb(void* ptr, size_t size, size_t nmemb, void* userdata) {
    std::string* resp = (std::string*)userdata;
    resp->append((char*)ptr, size * nmemb);
    return size * nmemb;
}
int main() {
    CURL* curl = curl_easy_init();
    if (!curl) return -1;
    std::string response;
    curl_easy_setopt(curl, CURLOPT_URL, "https://httpbin.org/ip");
    // HTTP proxy
    curl_easy_setopt(curl, CURLOPT_PROXY, "http://127.0.0.1:8080");
    // Proxy username and password
    curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME, "user");
    curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD, "pass");
    // Automatically detect HTTP / HTTPS
    curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15L);
    CURLcode res = curl_easy_perform(curl);
    if (res != CURLE_OK) {
        std::cerr << curl_easy_strerror(res) << std::endl;
    } else {
        std::cout << response << std::endl;
    }
    curl_easy_cleanup(curl);
    return 0;
}

SOCKS5 Proxy + Username and Password (Complete Example)

Using HTTP/Socks5 Proxy in Go (with Username and Password)

Method 1: net/http (Most Common)

Method 2: golang.org/x/net/proxy

Using HTTP/Socks5 Proxy in Java (with Username and Password)

HTTP Proxy + Username and Password

SOCKS5 + Username and Password

Using HTTP/Socks5 Proxy in Python (with Username and Password)

HTTP Proxy + Username and Password

SOCKS5 Proxy + Username and Password

Using HTTP/Socks5 Proxy in Node.js (with Username and Password)

Last updated