选择国家
如果您想访问特定位置的IP,您需要在用户字符串中提供一个带有两字母国家代码的country
参数。以下是国家参数列表:
Country
Country code
美国
country-US
德国
country-DE
法国
country-FR
荷兰
country-NL
英国
country-GB
罗马尼亚
country-RO
墨西哥
country-MX
日本
country-JP
例如,如果您只想轮换美国代理池,请在用户字符串中将轮换端口8000
与参数country-US
一起使用:
curl -x dc.oxylabs.io:8000 -U 'user-USERNAME-country-US:PASSWORD' https://ip.oxylabs.io/location
curl -x dc.oxylabs.io:8000 -U 'user-USERNAME-country-COUNTRY:PASSWORD' https://ip.oxylabs.io/location
import requests
username = 'USERNAME'
password = 'PASSWORD'
country = 'COUNTRY'
proxy = 'dc.oxylabs.io:8000'
proxies = {
"https": ('https://user-%s-country-%s:%s@%s' % (username, country, password, proxy))
}
response=requests.get("https://ip.oxylabs.io/location", proxies=proxies)
print(response.content)
const axios = require("axios");
const https = require("https");
const client = axios.create({
httpsAgent: new https.Agent({
rejectUnauthorized: false,
}),
});
const username = 'USERNAME';
const country = 'COUNTRY'
const password = 'PASSWORD'
client
.get("https://ip.oxylabs.io/location", {
proxy: {
protocol: "https",
host: "dc.oxylabs.io",
port: 8000,
auth: {
username: `user-${username}-country-${country}`,
password: password,
},
},
})
.then((res) => {
console.log(res.data);
})
.catch((err) => console.error(err));
<?php
$username = 'USERNAME';
$country = 'COUNTRY';
$password = 'PASSWORD';
$proxy = 'dc.oxylabs.io:8000';
$target = 'https://ip.oxylabs.io/location';
$request = curl_init($target);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_PROXY, $proxy);
curl_setopt($request, CURLOPT_PROXYUSERPWD, "user-$username-country-$country:$password");
$responseBody = curl_exec($request);
$error = curl_error($request);
curl_close($request);
if ($responseBody !== false) {
echo 'Response: ' . $responseBody;
} else {
echo 'Failed to connect to proxy: ' . $error;
}
package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
username, country, password, entry := "USERNAME", "COUNTRY", "PASSWORD", "dc.oxylabs.io:8000"
proxy, err := url.Parse(fmt.Sprintf("https://user-%s-country-%s:%s@%s", username, country, password, entry))
if err != nil {
panic(err)
}
transport := &http.Transport{
Proxy: http.ProxyURL(proxy),
}
client := &http.Client{Transport: transport}
target := "https://ip.oxylabs.io/location"
response, err := client.Get(target)
if err != nil {
panic(err)
}
defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
panic(err)
}
fmt.Println("Response:")
fmt.Println(string(body))
}
package com.example;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Base64;
import org.apache.hc.client5.http.fluent.Request;
import org.apache.hc.core5.http.HttpHost;
public class App {
public static void main(String[] args) throws IOException, URISyntaxException {
String targetUrl = "http://ip.oxylabs.io/location";
String username = "USERNAME";
String country = "COUNTRY";
String password = "PASSWORD";
String proxy = "dc.oxylabs.io:8000";
URI proxyURI = new URI(String.format("https://user-%s-country-%s:%s@%s", username, country, password, proxy));
String basicAuth = new String(
Base64.getEncoder()
.encode(
proxyURI.getUserInfo().getBytes()));
String response = Request.get(targetUrl)
.addHeader("Proxy-Authorization", "Basic " + basicAuth)
.viaProxy(HttpHost.create(proxyURI))
.execute().returnContent().asString();
System.out.println(response);
}
}
using System.Net;
// .NET currently does not support HTTPS proxies
var proxy = new WebProxy {
Address = new Uri("dc.oxylabs.io:8000"),
Credentials = new NetworkCredential(
userName: "user-USERNAME-country-COUNTRY",
password: "PASSWORD"
)
};
var httpClientHandler = new HttpClientHandler {Proxy = proxy};
using var client = new HttpClient(handler: httpClientHandler, disposeHandler: true);
var result = await client.GetStringAsync("https://ip.oxylabs.io/location");
Console.WriteLine(result);
订阅方法的区别
按IP付费的数据中心用户提供轮换端口和国家参数时,每次新请求将从其代理列表中接收选定国家的随机IP。
按流量付费的数据中心用户提供轮换端口和国家参数时,每次新请求将从整个代理池中接收选定国家的随机IP。
我们使用 MaxMind GeoIP2 数据库来确定IP位置。
Last updated