提出请求
在本节中,我们将展示使用我们创建的代理字符串的实际示例。我们将重点介绍如何设置HTTP/HTTPS和SOCKS5连接,并通过各种编程语言的示例进行说明。
请记住,端口将根据协议(HTTP/SOCKS5)而有所不同。
HTTP/HTTPS
curl -v -x geo.iproyal.com:12321:username123:password321_country-us_state-california -L https://ipv4.icanhazip.com
<?php
$url = 'https://ipv4.icanhazip.com';
$proxy = 'geo.iproyal.com:12321';
$proxyAuth = 'username123:password321_country-us_state-california';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
const axios = require('axios');
const url = 'https://ipv4.icanhazip.com';
const proxyOptions = {
host: 'geo.iproyal.com',
port: 12321,
auth: {
username: 'username123',
password: 'password321_country-us_state-california'
}
};
axios.get(url, { proxy: proxyOptions })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error);
});
import requests
url = 'https://ipv4.icanhazip.com'
proxy = 'geo.iproyal.com:12321'
proxy_auth = 'username123:password321_country-us_state-california'
proxies = {
'http': f'http://{proxy_auth}@{proxy}',
'https': f'http://{proxy_auth}@{proxy}'
}
response = requests.get(url, proxies=proxies)
print(response.text)
SOCKS5
curl -v --socks5 geo.iproyal.com:32325 --proxy-user username123:password321_country-us_state-california -L https://ipv4.icanhazip.com
<?php
$url = 'https://ipv4.icanhazip.com';
$proxy = 'geo.iproyal.com:32325';
$proxyAuth = 'username123:password321_country-us_state-california';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
const axios = require('axios');
const SocksProxyAgent = require('socks-proxy-agent');
const url = 'https://ipv4.icanhazip.com';
const socksProxy = 'socks5://username123:password321_country-us_state-california@geo.iproyal.com:32325';
const agent = new SocksProxyAgent(socksProxy);
axios.get(url, { httpAgent: agent, httpsAgent: agent })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error);
});
import requests
url = 'https://ipv4.icanhazip.com'
socks5_proxy = 'socks5://username123:password321_country-us_state-california@geo.iproyal.com:32325'
proxies = {
'http': socks5_proxy,
'https': socks5_proxy
}
response = requests.get(url, proxies=proxies)
print(response.text)
Last updated