程序中代理请求访问第三方地址

Linux Wget

# 如果代理不需要用户名和密码,不写「[代理用户名]:[代理密码]@」即可
# 设置多个 Header 信息,是要写多个 header 参数即可
# -Y on 打开代理
wget -Y on -e "http_proxy=http://[代理用户名]:[代理密码]@代理地址:代理端口号" 访问的地址 -O 保存的路径和文件名称 --tries=重试次数 --retry-connrefused --timeout=超时时间 --header="User-Agent: UA信息" --header="Host: host 信息" --referer ="请求来源地址"

PHP cURL

// 代理协议  CURLPROXY_HTTP (默认值,代理为 HTTP、HTTPS 都设置此值)、 CURLPROXY_SOCKS4、 CURLPROXY_SOCKS5、 CURLPROXY_SOCKS4A、CURLPROXY_SOCKS5_HOSTNAME
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);

// 代理地址
curl_setopt($ch, CURLOPT_PROXY, $strProxyServer);

// 代理端口号,也可以写在代理地址里面
curl_setopt($ch, CURLOPT_PROXYPORT, $strProxyPort);

// 代理的用户名和密码
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$strProxyUser:$strProxyPassWord");

PHP file_get_contents

无需账号密码的代理

$arrContext = [
    'http' => [
        'method' => 'GET',
        'header' => [ // 设置 header 头
            'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) Gecko/20100101 Firefox/56.0',
            .... 其它想设置的信息
        ], 
        'proxy'           => 'tcp://代理地址:代理端口号',
        'timeout'         => 10,
        'request_fulluri' => true,
    ],
];

$resContext  = stream_context_create($arrContext);
$strContents = file_get_contents('需要访问的地址', false, $resContext);

需要账号密码的代理

$strProxyAuth = base64_encode('代理账号:代理密码');

$arrContext = [
    'http' => [
        'method' => 'GET',
        'header' => [ // 设置 header 头
            'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) Gecko/20100101 Firefox/56.0',
            "Proxy-Authorization: Basic $strProxyAuth",
        ], 
        'proxy'           => 'tcp://代理地址:代理端口号',
        'timeout'         => 5,
        'request_fulluri' => true,
    ],
];

$resContext  = stream_context_create($arrContext);
$strContents = file_get_contents('需要访问的地址', false, $resContext);
知识共享许可协议
本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。
随喜
支付宝随喜
微信随喜

A dog’s face can very easily give away their guilt. It doesn’t help when they are standing directly in front of the mess they just created. But admit it, you stay mad for about 10 seconds and then you have to laugh at the situation standing before you. Jordan 11 Concord 2018 http://www.jordan11-concord.com/

Propecia Precio 1 Mg Generic Lasix No Prescription <a href=http://ordercheapvia.com>generic viagra</a> Pills Online Canada Propecia Bei Geheimratsecken

Levitra Milano Side Effects Of Amoxicillin In Infant <a href=http://lapizmoon.com>tadalafil cialis from india</a> Citoteque Como Comprar Rj Finasteride Precio Espana Propecia

Keflex Purpose <a href=http://prilipills.com>stendra priligy</a> Amoxicillin Causes Liver Damage Cialis In Farmacia Prezzo