# 发起请求

向……发起请求 `https://ip.oxylabs.io/location` 使用列表中的第一个专用数据中心代理。替换 `USERNAME` 和 `PASSWORD` 为你的代理用户凭据。&#x20;

{% hint style="info" %}
使用 [**ip.oxylabs.io/location**](https://ip.oxylabs.io/location) 来检查你的 IP 参数——该域名提供来自四个地理位置数据库的信息：MaxMind、IP2Location、DB-IP 和 IPinfo.io。这些参数包括 IP 地址、提供商、国家、城市、邮政编码、ASN、组织名称、时区以及元数据（当数据库披露时）。
{% endhint %}

```sh
curl -x ddc.oxylabs.io:8001 -U "user-USERNAME:PASSWORD" https://ip.oxylabs.io/location 
```

请注意，您必须遵循上面构建用户名字符串的示例，才能成功发出请求。追加 `用户-` 将字符串输入到您的用户名中，并注意凭据区分大小写。

**代码示例**

{% tabs %}
{% tab title="cURL" %}

```sh
curl -x ddc.oxylabs.io:8001 -U "user-USERNAME:PASSWORD" https://ip.oxylabs.io/location 
```

{% endtab %}

{% tab title="Python" %}

```python
导入 requests

用户名 = 'USERNAME'
密码 = 'PASSWORD'
代理 = 'ddc.oxylabs.io:8001'

代理 = {
   "https": ('https://user-%s:%s@%s' % (username, password, proxy))
}

response=requests.get("https://ip.oxylabs.io/location", 代理=代理)

print(response.content)
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
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", {
        代理: {
            协议: "https",
            主机: "ddc.oxylabs.io",
            端口: 8001,
            认证: {
                用户名: `user-${username}`,
                密码: password,
            },
        },
    })
    .then((res) => {
        console.log(res.data);
    })
    .catch((err) => console.error(err));

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$username = 'USERNAME';
$password = 'PASSWORD';
$proxy = 'https://ddc.oxylabs.io:8001';
$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 '响应: ' . $responseBody;
} else {
    echo '连接代理失败: ' . $error;
}
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"net/url"
)

func main() {
	username, password, entry := "USERNAME", "PASSWORD", "ddc.oxylabs.io:8001"
	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("响应:")
	fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Java" %}

```java
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 = "ddc.oxylabs.io:8001";

        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);
    }
}

```

{% endtab %}

{% tab title="C#" %}

```csharp
using System.Net;

// .NET 目前不支持 HTTPS 代理
var proxy = new WebProxy {
    Address = new Uri("http://ddc.oxylabs.io:8001"),
    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);
```

{% endtab %}
{% endtabs %}

代理列表中的第一个 IP 将始终使用`8001` 端口。若要使用不同的代理发出请求，你需要找到你的 [**代理列表**](/products/cn/dai-li/dedicated-datacenter-proxies/self-service/proxy-list.md) 并从那里获取端口值。&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.oxylabs.io/products/cn/dai-li/dedicated-datacenter-proxies/self-service/making-requests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
