如何设置代理IP?常用工具及语言

2019-01-24  本文已影响0人  佑岷

本文列举常用语言or工具如何配置or设置代理IP。

curl -x http://PROXYHOST:PORT -U USERNAME:PASSWORD http://example.com
http_proxy="http://PROXYHOST:PORT" wget --proxy-user=USERNAME --proxy-password=PASSWORD http://example.com
>>> import requests
>>> proxies = {'http': 'http://USERNAME:PASSWORD@PROXYHOST:PORT', 'https': 'http://USERNAME:PASSWORD@PROXYHOST:PORT'}
>>> response = requests.get('http://example.com', proxies=proxies)
方法一:
Using HTTParty
HTTParty.get(url, { http_proxyaddr: "PROXYHOST", http_proxyport: "PORT", http_proxyuser: "USERNAME", http_proxypass: "PASSWORD", :timeout => 3 })
方法二:
Using typhoeus
options = {proxy: 'http://PROXYHOST:PORT', proxyuserpwd: 'USERNAME:PASSWORD'}
req = Typhoeus::Request.new(url, options)
req.run
PhantomJS:
> page.customHeaders={'Proxy-Authorization': 'Basic '+btoa('USERNAME:PASSWORD')};
CasperJS:
casper.page.customHeaders = 'Proxy-Authorization': "Basic #{btoa('USERNAME:PASSWORD')}"
HttpClient client = new HttpClient();
HttpConnectionManager conManager = client.getHttpConnectionManager();
client.getHostConfiguration().setProxy("PROXYHOST", PORT);
HttpState state = new HttpState();
state.setProxyCredentials(null, null, new UsernamePasswordCredentials("USERNAME", "PASSWORD"));
client.setState(state);
WebProxy ProxyString = new WebProxy("http://PROXYHOST:PORT", true);
//set network credentials may be optional
NetworkCredential proxyCredential = new NetworkCredential("USERNAME", "PASSWORD");
ProxyString.Credentials = proxyCredential;
WebRequest.DefaultWebProxy =  ProxyString;

HttpWebRequest request = (HttpWebRequest);
//manually set authorization header
string authInfo = "USERNAME" + ":" + "PASSWORD";
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Headers["Proxy-Authorization"] = "Basic " + authInfo;
<%
Const HTTPREQUEST_PROXYSETTING_PROXY        = 2
Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY  = 1

Dim responseText

With Server.CreateObject("WinHttp.WinHttpRequest.5.1")
    .SetProxy HTTPREQUEST_PROXYSETTING_PROXY, "PROXYHOST:PORT"
    .Open "GET", "http://example.com"
    .SetCredentials "USERNAME", "PASSWORD", HTTPREQUEST_SETCREDENTIALS_FOR_PROXY
    .Send
    responseText = .ResponseText
End With
%>

FROMhttp-client-examples

上一篇下一篇

猜你喜欢

热点阅读