提出请求
默认情况下,Oxylabs 代理和代理轮换工具使用基础 HTTP 身份验证,需要您发送用户名和密码。您可以通过 support@oxylabs.io联系您的专属客户经理或我们的支持团队获取您的凭证。
我们还支持基于白名单 IP 地址的身份验证; 请参阅 将 IP 列入白名单。根据身份验证方法的不同,您可能需要更改代理端口。
代理端口 | 用途 |
---|---|
| 使用登录凭据(用户名和密码)时,代理需要此端口。它还与 代理轮换工具 配合使用,同时使用登录凭据和白名单 IP。 |
| 当通过白名单 IP 完成授权时,代理需要此端口。 |
代码示例
如果您想通过用户名和密码身份验证方法使用静态数据中心代理:
curl -x 1.2.3.4:60000 -U user1:pass1 http://ip.oxylabs.io
<?php
$username = 'user1';
$password = 'pass1';
$proxy = '1.2.3.4:60000';
$query = curl_init('https://ip.oxylabs.io');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
curl_setopt($query, CURLOPT_PROXYUSERPWD, "$username:$password");
$output = curl_exec($query);
curl_close($query);
if ($output)
echo $output;
?>
import requests
response = requests.get(
'https://ip.oxylabs.io/location',
proxies={'http': 'http://username:password@1.2.3.4:60000',
'https': 'http://username:password@1.2.3.4:60000'}
)
print(response.text)
using System;
using System.Net;
class Example
{
static void Main()
{
var proxy = new WebProxy
{
Address = new Uri($"http://1.2.3.4:60000"),
BypassProxyOnLocal = false,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("username", "password")
};
var handler = new HttpClientHandler
{
Proxy = proxy,
};
HttpClient client = new HttpClient(handler);
var task = Task.Run(async () =>
{
var response = await client.GetAsync("https://ip.oxylabs.io/location");
var content = response.Content;
var result = await content.ReadAsStringAsync();
return result;
});
task.Wait();
Console.WriteLine(task.Result);
}
}
如果您想通过列入白名单 IP 身份验证方法使用静态数据中心代理:
curl -x 1.2.3.4:65432 https://ip.oxylabs.io
<?php
$proxy = '1.2.3.4:65432';
$query = curl_init('https://ip.oxylabs.io');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
$output = curl_exec($query);
curl_close($query);
if ($output)
echo $output;
?>
import requests
response = requests.get(
'https://ip.oxylabs.io',
proxies={'http': 'http://1.2.3.4:65432',
'https': 'http://1.2.3.4:65432'}
)
print(response.text)
using System;
using System.Net;
class Example
{
static void Main()
{
var proxy = new WebProxy
{
Address = new Uri($"http://1.2.3.4:65432"),
BypassProxyOnLocal = false,
UseDefaultCredentials = false,
};
var handler = new HttpClientHandler
{
Proxy = proxy,
};
HttpClient client = new HttpClient(handler);
var task = Task.Run(async () =>
{
var response = await client.GetAsync("https://ip.oxylabs.io/location");
var content = response.Content;
var result = await content.ReadAsStringAsync();
return result;
});
task.Wait();
Console.WriteLine(task.Result);
}
}
Last updated