get-current-proxy
URL (API endpoint)
Request URL
https://tmproxy.com/api/proxy/get-current-proxyRequest body
api_key 是您从 TMProxy 购买的 API 密钥
Example Value
{
"api_key": "API_KEY"
}Schema
responseCurrentProxy{
code integer
message string
data
Proxy{
ip_allow string
允许使用代理的 IP,无需输入代理的用户名和密码(可用于 ipv4 代理)
username string
代理用户名,用于代理身份验证(适用于 IPv4 代理和 IPv6 代理)
password string
代理密码,用于验证 socks5/https 代理(可用于 ipv4 代理和 ipv6 代理)
public_ip string
代理的公共 IP
isp_name string
ISP 名称
location_name string
区域名称
socks5 string
使用SOCK5 v5协议的代理
https string
使用 HTTP/HTTPS 协议的代理
timeout integer
代理有效期. 0 = lifetime
next_request integer
最短可更换IP的剩余时间
expired_at integer
代理将在 过期。如果 expired_at 为空,则代理永不过期。
}
} Server response OK
Response body - code 200
{
"code": 0,
"message": "string",
"data": {
"ip_allow": "string",
"username": "string",
"password": "string",
"public_ip": "string",
"isp_name": "string",
"location_name": "string",
"socks5": "string",
"https": "string",
"timeout": 0,
"next_request": 0,
"expired_at": 0
}
}Example Code
JavaScript (fetch API)
fetch('https://tmproxy.com/api/proxy/get-current-proxy', {
method: 'POST',
headers: {
'accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ "api_key": "API_KEY" })
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));Python (requests library)
import requests
url = "https://tmproxy.com/api/proxy/get-current-proxy"
headers = {
"accept": "application/json",
"Content-Type": "application/json"
}
data = {
"api_key": "API_KEY"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://tmproxy.com/api/proxy/get-current-proxy"
data := map[string]string{"api_key": "API_KEY"}
jsonData, err := json.Marshal(data)
if err != nil {
panic(err)
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
panic(err)
}
req.Header.Set("accept", "application/json")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}Curl
curl -X POST "https://tmproxy.com/api/proxy/get-current-proxy" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"api_key\":\"API_KEY\"}"PHP (cURL)
<?php
$url = "https://tmproxy.com/api/proxy/get-current-proxy";
$data = array("api_key" => "API_KEY");
$jsonData = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"accept: application/json",
"Content-Type: application/json"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
die("cURL Error: " . curl_error($ch));
}
curl_close($ch);
if (json_last_error() !== JSON_ERROR_NONE) {
die("JSON Error: " . json_last_error_msg());
}
echo $response;
?>
Java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class Main {
public static void main(String[] args) throws Exception {
URL url = new URL("https://tmproxy.com/api/proxy/get-current-proxy");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
String jsonInputString = "{\"api_key\":\"API_KEY\"}";
try(OutputStream os = con.getOutputStream()) {
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input, 0, input.length);
}
try(BufferedReader br = new BufferedReader(
new InputStreamReader(con.getInputStream(), "utf-8"))) {
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
}
}C#
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
public class Example
{
public static async Task Main(string[] args)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent("{\"api_key\":\"API_KEY\"}", Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://tmproxy.com/api/proxy/get-current-proxy", content);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
}