数据中心代理
用户凭证
要开始使用Oxylabs的数据中心代理,您首先需要前往Oxylabs的仪表板并购买适合您需求的计划。 之后,您将被引导创建您的代理用户。代理用户凭证是您访问数据中心代理的凭证。
发出请求
在您创建代理用户之后,系统会弹出一个窗口,显示您的第一个测试请求以接收一个随机IP。
复制它并将USERNAME
和PASSWORD
参数更改为您的代理凭证:
curl -x dc.oxylabs.io:8000 -U "user-USERNAME:PASSWORD" https://ip.oxylabs.io/location
在下方找到更多其他编程语言的代码示例:
curl -x dc.oxylabs.io:8000 -U "user-USERNAME:PASSWORD" https://ip.oxylabs.io/location
import requests
username = 'USERNAME'
password = 'PASSWORD'
proxy = 'dc.oxylabs.io:8000'
proxies = {
"https": ('https://user-%s:%s@%s' % (username, 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 password = 'PASSWORD'
client
.get("https://ip.oxylabs.io/location", {
proxy: {
protocol: "https",
host: "dc.oxylabs.io",
port: 8000,
auth: {
username: `user-${username}`,
password: password,
},
},
})
.then((res) => {
console.log(res.data);
})
.catch((err) => console.error(err));
<?php
$username = 'USERNAME';
$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:$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, password, entry := "USERNAME", "PASSWORD", "dc.oxylabs.io:8000"
proxy, err := url.Parse(fmt.Sprintf("https://user-%s:%s@%s", username, 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 target = "http://ip.oxylabs.io/location";
String username = "USERNAME";
String password = "PASSWORD";
String proxy = "dc.oxylabs.io:8000";
URI proxyURI = new URI(String.format("https://user-%s:%s@%s", username, password, proxy));
String basicAuth = new String(
Base64.getEncoder()
.encode(
proxyURI.getUserInfo().getBytes()));
String response = Request.get(target)
.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",
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.oxylabs.io/location 检查您的IP参数——该域名提供来自四个地理位置数据库的信息:MaxMind、IP2Location、DB-IP 和 IPinfo.io。参数包括IP地址、提供商、国家、城市、邮政编码、ASN、组织名称、时区和元数据(由数据库披露时)。
Last updated