支持各种热门编程语言,轻松的集成到您的项目
cURL 代理示例
curl -x api.mayihttp.com:12984 -U "user:password" ipinfo.io
Python 代理示例
import requests
# 配置代理服务器(包含账号密码认证)
proxies = {
'http': 'http://user:password@api.mayihttp.com:12984',
'https': 'http://user:password@api.mayihttp.com:12984'
}
try:
response = requests.get('http://ipinfo.io', proxies=proxies, timeout=10)
print(response.text)
except Exception as e:
print(f"请求失败: {e}")
C# 代理示例
using System;
using System.Net;
using System.Net.Http;
class ProxyExample
{
static async Task Main()
{
var proxy = new WebProxy("http://api.mayihttp.com:12984")
{
Credentials = new NetworkCredential("user", "password")
};
var handler = new HttpClientHandler
{
Proxy = proxy,
UseProxy = true
};
using (var client = new HttpClient(handler))
{
var response = await client.GetAsync("http://ipinfo.io");
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}
Go 代理示例
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
func main() {
proxyURL, _ := url.Parse("http://user:password@api.mayihttp.com:12984")
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyURL),
},
}
resp, err := client.Get("http://ipinfo.io")
if err != nil {
fmt.Println("请求失败:", err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
Node.js 代理示例
const axios = require('axios');
const proxy = {
host: 'api.mayihttp.com',
port: 12984,
auth: {
username: 'user',
password: 'password'
}
};
axios.get('http://ipinfo.io', { proxy })
.then(response => console.log(response.data))
.catch(error => console.error('请求失败:', error));
Java 代理示例
import java.io.*;
import java.net.*;
import java.util.Base64;
public class ProxyExample {
public static void main(String[] args) {
try {
// 配置代理
Proxy proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("api.mayihttp.com", 12984));
URL url = new URL("http://ipinfo.io");
HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
// 添加认证
String auth = "user:password";
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedAuth);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
PHP 代理示例
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://ipinfo.io');
curl_setopt($ch, CURLOPT_PROXY, 'api.mayihttp.com:12984');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo '请求失败: ' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
?>