账密DEMO示例
C/C++
Go
Java
Node.js
PHP
Python
                  
#include "iostream"
#include "curl/curl.h"

size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}
                      
int main() {
    CURL* curl;
    CURLcode res;
    std::string readBuffer;

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://www.ipcool.net/app-api/getIp");
        curl_easy_setopt(curl, CURLOPT_PROXY, "http://ip:port");
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);

        res = curl_easy_perform(curl);
        if (res != CURLE_OK) {
            std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
        } else {
            std::cout << readBuffer << std::endl;
        }

        curl_easy_cleanup(curl);
    }
    return 0;
}
                  
                
                  
package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
    "net/url"
)

func main() {
    proxyUrl, _ := url.Parse("http://ip:port")
    transport := &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
    client := &http.Client{Transport: transport}

    req, err := http.NewRequest("GET", "https://www.ipcool.net/app-api/getIp", nil)
    if err != nil {
        fmt.Println("Error creating request:", err)
        return
    }

    resp, err := client.Do(req)
    if err != nil {
        fmt.Println("Error sending request:", err)
        return
    }
    defer resp.Body.Close()

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println("Error reading response:", err)
        return
    }

    fmt.Println(string(body))
}
                  
                
                  
import java.io.*;
import java.net.*;

public class HttpClient {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://www.ipcool.net/app-api/getIp");
            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("ip", port));
            HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
            connection.setRequestMethod("GET");

            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            StringBuilder content = new StringBuilder();

            while ((inputLine = in.readLine()) != null) {
                content.append(inputLine);
            }

            in.close();
            connection.disconnect();
            System.out.println(content.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
                  
                
                  
require('request-promise')({
    url: 'https://www.ipcool.net/app-api/getIp',
    proxy: 'http://ip:port',
})
.then(function(data){ console.log(data); },
    function(err){ console.error(err); });
                  
                
                  
$proxy = "http://ip:port";
$url = "https://www.ipcool.net/app-api/getIp";
$options = [
    "http" => [
        "proxy" => $proxy,
        "request_fulluri" => true,
    ],
];
$context = stream_context_create($options);

try {
    $response = file_get_contents($url, false, $context);
    echo $response;
} catch (Exception $e) {
    echo $e->getMessage();
}
                  
                
                        
import requests

proxy = {"http": "http://ip:port", "https": "http://ip:port"}
url = "https://www.ipcool.net/app-api/getIp"

try:
    response = requests.get(url, proxies=proxy)
    print(response.text)
except requests.exceptions.RequestException as e:
    print(e)