How to configure proxies

Code examples for proxy authentication

Choose your programming language

Below you can find code examples for 7 most used programming languages on the market.

To set up our proxies simply choose the code accordingly to the programing language you are using:

                      
  require('request-promise') ({
    url: 'https://ipinfo.io/ip',
    proxy: 'http://username:password@server.proxyland.io:9090'
  }).then(function(data ){
    console.log(data);
  }, function(err){
    console.error(err);
  });
                      
                    
                    
  $username = 'username';
  $password = 'password';

  $proxy = 'server.proxyland.io:9090';
  $target = curl_init('https://ipinfo.io/ip');

  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);
  echo $result;

                  
  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 = "https://ipinfo.io/ip";

          var proxy = new WebProxy("server.proxyland.io:9090")
          {
              UseDefaultCredentials = false,

              Credentials = new NetworkCredential(
                  userName: "username",
                  password: "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();

          }
      }
  }
                  
                    
  import urllib.request as request

  url = 'https://ipinfo.io'
  username = 'username'
  password = 'password'

  proxy = ('http://%s:%s@server.proxyland.io:9090' % (username, password))

  query = request.build_opener(request.ProxyHandler({ 'http': proxy }))

  print(query.open(url).read())
                    
                  
                      
  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("server.proxyland.io", 9090); // Set proxy IP/port.
        Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress);
        URL url = new URL("http://ipinfo.io/ip"); //enter target URL
        Authenticator authenticator = new Authenticator() {
           public PasswordAuthentication getPasswordAuthentication() {
              return (new PasswordAuthentication("username","password".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();

     }
  }

                    
                      
  require "uri"
  require 'net/http'

  proxy_host = 'server.proxyland.io:9090'
  proxy_port = 9090
  proxy_user = 'username'
  proxy_pass = 'password'

  uri = URI.parse('http://ipinfo.io/ip')
  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

                    
                      
  package main

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

  const (
  	resourceUrl = "https://ipinfo.io"
  	proxyHost   = "server.proxyland.io:9090"
  	username    = "username"
  	password    = "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)
}

                    
arrow-up icon