基本代理验证

代理验证的代码示例

1.选择您的编程语言

Smartproxy提供了市场上7种最常用的编程语言的代码示例:

需要更多示例吗? 请到我们 GitHub 页面

2. 设置代码

import requests

url = 'http://ip.smartdaili-china.com/json'
username = '账号'
password = '密码'

proxy = f'https://user-{username}:{password}@china-gate.visitxiangtan.com:8000'

response = requests.get(url, proxies={'http': proxy, 'https': proxy})

print(response.text)
require('request-promise') ( { 

   url: 'http://ip.smartdaili-china.com/json', 
   proxy: 'http://账号:密码@gate.visitxiangtan.com:7000' 

}).then( 
   function(data ){ 
      console.log(data); 
    }, 
    function(err){ 
       console.error(err); 
   } 
);
import java.net.*; 
import java.io.*; 
import java.util.Scanner; 

public class ProxyTest 
{ 
   public static void main(String[] args) throws Exception 
   { 
      InetSocketAddress proxyAddress = new InetSocketAddress("gate.visitxiangtan.com", 7000); // Set proxy IP/port. 
      Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress); 
      URL url = new URL("http://ip.smartdaili-china.com/json"); //enter target URL 
      Authenticator authenticator = new Authenticator() { 
         public PasswordAuthentication getPasswordAuthentication() { 
            return (new PasswordAuthentication("账号","密码".toCharArray())); //enter credentials 
         } 
      }; 


      Authenticator.setDefault(authenticator); 
   URLConnection urlConnection = url.openConnection(proxy); 


//Scanner to view output 

Scanner scanner = new Scanner(urlConnection.getInputStream()); 
   System.out.println(scanner.next()); 
   scanner.close(); 

   } 
}
<?php
$username = '账号';
$password = '密码';
$proxy = 'gate.visitxiangtan.com:7000';
$target = curl_init('http://ip.smartdaili-china.com/json');
curl_setopt($target, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($target, CURLOPT_PROXY, $proxy);
curl_setopt($target, CURLOPT_PROXYUSERPWD, "$username:$password");
$result = curl_exec($target);
curl_close($target);
if ($result) {
    echo $result;
}
?>
require "uri" 
require 'net/http' 

proxy_host = 'gate.visitxiangtan.com' 
proxy_port = 7000 
proxy_user = '账号' 
proxy_pass = '密码' 

uri = URI.parse('http://ip.smartdaili-china.com/json') 
proxy = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass) 

req = Net::HTTP::Get.new(uri.path) 

result = proxy.start(uri.host, uri.port) do |http| 
   http.request(req) 
end 

puts result.body
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        Task t = new Task(DownloadPageAsync);
        t.Start();
        Console.ReadLine();
    }

    static async void DownloadPageAsync()
    {
        string page = "http://ip.smartdaili-china.com/json";

        var proxy = new WebProxy("gate.visitxiangtan.com:7000")
        {
            UseDefaultCredentials = false,

            Credentials = new NetworkCredential(
                userName: "账号",
                password: "密码")
        };

        var httpClientHandler = new HttpClientHandler()
        {
            Proxy = proxy,
        };

        var client = new HttpClient(handler: httpClientHandler, disposeHandler: true);
        var response = await client.GetAsync(page);
        using (HttpContent content = response.Content)
        {
            string result = await content.ReadAsStringAsync();
            Console.WriteLine(result);
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();

        }
    }
}
package main

import (
    "encoding/json"
    "fmt"
    "log"
    "net/http"
    "net/url"
)

const (
    resourceUrl = "http://ip.smartdaili-china.com/json"
    proxyHost   = "gate.visitxiangtan.com:7000"
    username    = "账号"
    password    = "密码"
)

func main() {
    proxyUrl := &url.URL{
        Scheme: "http",
        User:   url.UserPassword(username, password),
        Host:   proxyHost,
    }

    client := http.Client{
        Transport: &http.Transport{
            Proxy: http.ProxyURL(proxyUrl),
        },
    }

    resp, err := client.Get(resourceUrl)
    if err != nil {
        log.Fatal(err)
    }
    defer resp.Body.Close()

    var body map[string]interface{}
    if err = json.NewDecoder(resp.Body).Decode(&body); err != nil {
        log.Fatal(err)
    }

    fmt.Println(body)
}

3. 变动参数

url = 'http://ip.smartdaili-china.com/json'
username = '账号'
password = '密码'
url: 'http://ip.smartproxy.com/json', 
proxy: 'http://账号:密码@gate.smartproxy.com:7000'
InetSocketAddress proxyAddress = new InetSocketAddress("gate.smartproxy.com", 7000); // Set proxy IP/port. 
      Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress); 
      URL url = new URL("http://ip.smartproxy.com/json"); //enter target URL 
      Authenticator authenticator = new Authenticator() { 
         public PasswordAuthentication getPasswordAuthentication() { 
            return (new PasswordAuthentication("账号","密码".toCharArray())); //enter credentials
$username = '账号'; 
$password = '密码'; 
$proxy = 'gate.smartproxy.com:7000'; 
$target = curl_init('http://ip.smartproxy.com/json');
proxy_host = 'gate.smartproxy.com' 
proxy_port = 7000 
proxy_user = '账号' 
proxy_pass = '密码' 
uri = URI.parse('http://ip.smartproxy.com/json')
string page = "http://ip.smartproxy.com/json";

var proxy = new WebProxy("gate.smartproxy.com:7000")
{
        UseDefaultCredentials = false,

        Credentials = new NetworkCredential(
        userName: "账号",
        password: "密码")
};
resourceUrl = "http://ip.smartproxy.com/json"
proxyHost   = "gate.smartproxy.com:7000"
username    = "账号"
password    = "密码"