Configuration examples for HTTP Basic Proxy Authentication

Below are examples showing how to configure the Proxy Host with Basic Authentication in various HTTP clients.
Many Unix/Linux clients support the http_proxy environment variable, or even rely on it exclusively. For those clients, do the following:

ProxyMesh also supports IP address authentication, in which case you do not need to use a username and password in the examples below.
Instead, set the the http_proxy environment variable to http://PROXYHOST:PORT.

For web browsers, you must use IP address authentication, then configure your network proxy settings. If you use Firefox or Chrome, the FoxyProxy plugin makes it really easy to configure your proxy settings.


cURL understands the http_proxy environment variable, but if it is not set, you can also do the following:



Wget will use the http_proxy environment variable if it is set. The example below shows how to use wget if http_proxy is not set.

http_proxy="http://PROXYHOST:PORT" wget --proxy-user=USERNAME --proxy-password=PASSWORD


The best Python library for doing HTTP requests is Requests, specifically version 2.7.0 and greater. The example below shows the most reliable way to use proxy authentication, but you can omit the auth parameter if you're using IP authentication.

>>> import requests
>>> auth = requests.auth.HTTPProxyAuth('USERNAME', 'PASSWORD')
>>> proxies = {'http': 'http://PROXYHOST:PORT'}
>>> response = requests.get('', proxies=proxies, auth=auth)


For the scrapy crawling framework, you must set the http_proxy environment variable, as shown above, then activate the HttpProxyMiddleware.

PhantomJS and CasperJS

PhantomJS has a --proxy setting for specifying the proxy host:port. It also has a --proxy-auth setting that unfortunately doesn't work. So if you want to use username:password authentication, you must do the following in your code:

> page.customHeaders={'Proxy-Authorization': 'Basic '+btoa('USERNAME:PASSWORD')};

If you're using CasperJS then the syntax is slightly different: = 'Proxy-Authorization': "Basic #{btoa('USERNAME:PASSWORD')}"


For PHP, you can use the included Client URL Library (cURL). To configure proxy settings, use the curl_setopt function to set CURLOPT_PROXY to the proxy host and port, such as PROXYHOST:PORT. Optionally, for authentication, you can set CURLOPT_PROXYUSERPWD to USERNAME:PASSWORD.


There are many Java HTTP client that you can use. Here's a link to examples of using the Commons HTTP Client with Proxies. Example code is included below:

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

C# .Net

The following example code for C# .Net was provided by Michael Eisenstein:

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;

ASP VBScript

Dim responseText
With Server.CreateObject("WinHttp.WinHttpRequest.5.1")
	.Open "GET", ""
	responseText = .ResponseText
End With