> ## Documentation Index
> Fetch the complete documentation index at: https://help.decodo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Examples

> Basic Code Examples for Popular Programming Languages

## Programming Languages

Decodo offers code examples for 7 of the most used programming languages on the market:

<Columns cols={3}>
  <Column>
    * [**Python**](https://github.com/decodo/decodo/tree/master/python)
    * [**Node.js**](https://github.com/decodo/decodo/tree/master/nodejs)
    * [**Java**](https://github.com/decodo/decodo/tree/master/java)
  </Column>

  <Column>
    * [**PHP**](https://github.com/decodo/decodo/tree/master/php)
    * [**Ruby**](https://github.com/decodo/decodo/tree/master/ruby)
  </Column>

  <Column>
    * [**C#**](https://github.com/decodo/decodo/tree/master/csharp)
    * [**Golang**](https://github.com/decodo/decodo/tree/master/golang)
  </Column>
</Columns>

<Note>
  Visit our Decodo [**GitHub**](https://github.com/decodo/decodo) for more examples.
</Note>

## Code Setup

To set up our proxies, simply choose the code according to the programming language you wish to use in the table below:

<CodeGroup>
  ```python Python theme={null}
  import requests

  url = 'http://ip.decodo.com/json'
  username = 'username'
  password = 'password'

  proxy = f'http://{username}:{password}@gate.decodo.com:7000'
    
  response = requests.get(url, proxies={'http': proxy, 'https': proxy})

  print(response.text)
  ```

  ```javascript Node theme={null}
  const axios = require("axios");

  const url = "http://ip.decodo.com/json";
  const resp = axios.get(url, {
      proxy: {
          host: 'gate.decodo.com',
          port: 7000,
          auth: {
              username: 'username',
              password: 'password'
          }
      }
      
  }). then(resp => {
      console.log(resp.data);
  });
  ```

  ```java Java theme={null}
  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.decodo.com", 7000); // Set proxy IP/port. 
        Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress); 
        URL url = new URL("http://ip.decodo.com"); //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(); 

     } 
  }
  ```

  ```php PHP theme={null}
  <?php 
  $username = 'username'; 
  $password = 'password'; 
  $proxy = 'gate.decodo.com:7000'; 
  $target = curl_init('http://ip.decodo.com/'); 
  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; 
  ?>
  ```

  ```ruby Ruby theme={null}
  require "uri" 
  require 'net/http' 

  proxy_host = 'gate.decodo.com' 
  proxy_port = 7000 
  proxy_user = 'username' 
  proxy_pass = 'password' 

  uri = URI.parse('http://ip.decodo.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
  ```

  ```csharp C# theme={null}
  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.decodo.com/json";

          var proxy = new WebProxy("gate.decodo.com:7000")
          {
              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();

          }
      }
  }
  ```

  ```go Go theme={null}
  package main

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

  const 
  	resourceUrl = "http://ip.decodo.com/json"
  	proxyHost   = "gate.decodo.com:7000"
  	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)
  }
  ```
</CodeGroup>

## Changing Parameters

To edit your connection details, change the corresponding lines in your code:

<CodeGroup>
  ```python Python theme={null}
  url = 'http://ip.decodo.com/json'
  username = 'username'
  password = 'password'
  ```

  ```javascript Node theme={null}
  const url = "https://ip.decodo.com"; 
  username: 'username',
  password: 'password'
  ```

  ```java Java theme={null}
  InetSocketAddress proxyAddress = new InetSocketAddress("gate.decodo.com", 7000); // Set proxy address and port 
        Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress); 
        URL url = new URL("http://ip.decodo.com"); //enter target URL 
        Authenticator authenticator = new Authenticator() { 
           public PasswordAuthentication getPasswordAuthentication() { 
              return (new PasswordAuthentication("username","password".toCharArray())); //enter credentials
  ```

  ```php PHP theme={null}
  $username = 'username'; 
  $password = 'password'; 
  $proxy = 'gate.decodo.com:7000'; 
  $target = curl_init('http://ip.decodo.com/json');
  ```

  ```ruby Ruby theme={null}
  proxy_host = 'gate.decodo.com' 
  proxy_port = 7000 
  proxy_user = 'username' 
  proxy_pass = 'password' 
  uri = URI.parse('http://ip.decodo.com/json')
  ```

  ```csharp C# theme={null}
  string page = "http://ip.decodo.com/json";

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

  		Credentials = new NetworkCredential(
  		userName: "username",
  		password: "password")
  };
  ```

  ```go Go theme={null}
  resourceUrl = "http://ip.decodo.com/json"
  	proxyHost   = "gate.decodo.com:7000"
  	username    = "username"
  	password    = "password"
  ```
</CodeGroup>

<Note>
  ### Proxy Guides

  * Learn how to find **proxy details** in your dashboard for each proxy type [**here**](https://help.decodo.com/docs/proxy-quick-start-guides).
</Note>

***

<Columns cols={2}>
  <Card title="Support" href="https://direct.lc.chat/12092754" cta="Let's chat!">
    Need help or just want to say hello? Our support is available 24/7. \
    You can also reach us anytime via email at [support@decodo.com](mailto:support@decodo.com).
  </Card>

  <Card title="Feedback" href="mailto:feedback@decodo.com" cta="Share feedback">
    Can't find what you're looking for? Request an article! \
    Have feedback? Share your thoughts on how we can improve.
  </Card>
</Columns>
