PHP使用HTTP代码示例

// 要访问的目标页面
    $targetUrl = "http://ip.hahado.cn/ip";
    //$targetUrl = "http://ip.hahado.cn/switch-ip";
    //$targetUrl = "http://ip.hahado.cn/current-ip";
    // 代理服务器
    define("PROXY_SERVER", "ip.hahado.cn:39010");
    // 隧道身份信息
    define("PROXY_USER", "username");
    define("PROXY_PASS", "password");
    $proxyAuth = base64_encode(PROXY_USER . ":" . PROXY_PASS);
    $headers = implode("\r\n", [
        "Proxy-Authorization: Basic {$proxyAuth}",
        "Proxy-Switch-Ip: yes",
    ]);
    $options = [
        "http" => [
            "proxy"  => $proxyServer,
            "header" => $headers,
            "method" => "GET",
        ],
    ];
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    var_dump($result);

嵌入即可使用隧道模式HTTP来进行操作

你可能感兴趣的:(php,http,服务器,java,开发语言)