var request = require('request');
request({
'url':'http://ipinfo.io',
'method': "GET",
'proxy':'http://USERNAME:PASSWORD@Proxy Server:PORT'
},function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
})
import android.util.Log;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import okhttp3.Authenticator;
import okhttp3.Credentials;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;
public class HTTPDemo {
public static void curlhttp() {
final int proxyPort = PORT;
final String proxyHost = "Proxy Server";
final String username = "USERNAME";
final String password = "PASSWORD";
final String targetUrl = "http://ipinfo.io";
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
builder.proxyAuthenticator(new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
if(response.code() == 407) {
String credential = Credentials.basic(username, password);
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
}
return null;
}
});
OkHttpClient okHttpClient = builder
.build();
Request request = new Request.Builder().url(targetUrl).build();
try (Response response = okHttpClient.newCall(request).execute()) {
String str = response.body().string();
Log.d("----------http------", str);
} catch (Exception e) {
Log.d("----------http------", e.toString());
}
}
}
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static async Task Main(string[] args)
{
string user = "USERNAME";
string password = "PASSWORD";
var proxy = new WebProxy
{
Address = new Uri("http://Proxy Server:PORT"),
Credentials = new NetworkCredential(
userName: user,
password: password
),
};
var httpClientHandler = new HttpClientHandler { Proxy = proxy };
HttpClient client = new HttpClient(handler: httpClientHandler);
var requestMessage = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("http://ipinfo.io"),
};
var response = await client.SendAsync(requestMessage);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
client.Dispose();
}
}
}
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"time"
)
var proxyip = "http://USERNAME:PASSWORD@Proxy Server:PORT"
var domain = "http://ipinfo.io"
func main() {
u, _ := url.Parse(proxyip)
t := &http.Transport{
MaxIdleConns: 10,
MaxConnsPerHost: 10,
IdleConnTimeout: time.Duration(10) * time.Second,
//Proxy: http.ProxyURL(url),
Proxy: http.ProxyURL(u),
}
c := &http.Client{
Transport: t,
Timeout: time.Duration(10) * time.Second,
}
reqest, err := http.NewRequest("GET", domain, nil)
if err!=nil{
panic(err)
}
response, err := c.Do(reqest)
if err!=nil{
panic(err)
}
defer response.Body.Close()
res,err := ioutil.ReadAll(response.Body)
if err!=nil{
panic(err)
}
fmt.Println(string(res))
}
$username = "USERNAME";
$password = "PASSWORD";
$proxy_address = "Proxy Server";
$proxy_port = "PORT";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://ipinfo.io");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_PROXY, $proxy_address);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
if($output === FALSE ){
echo "CURL Error:".curl_error($ch);
} else {
echo $output;
}
curl_close($ch);
import requests
proxyip = "http://USERNAME:PASSWORD@Proxy Server:PORT"
url = "http://ipinfo.io"
proxies={
'http':proxyip,
'https':proxyip,
}
data = requests.get(url=url,proxies=proxies)
print(data.text)