> For the complete documentation index, see [llms.txt](https://docs.rapidproxy.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rapidproxy.io/proxies/code-sample.md).

# Code Sample

Explore Rapidproxy code samples for using residential proxies with cURL, Python, Node.js, Puppeteer, and Java. Learn how to configure proxy authentication and integrate proxies into your applications.

This page provides ready-to-use **code examples** for integrating Rapidproxy proxies in various programming languages and tools.\
Explore integration examples for Dynamic (Rotating) Residential Proxies, Static Residential Proxies, and Unlimited Residential Proxies using industry-standard authentication methods.

***

### 1. General Usage & How to Read These Examples

Rapidproxy supports multiple proxy authentication methods including:

* [**Username & Password Auth**](https://docs.rapidproxy.io/proxies/dynamic-residential-proxy/get-proxy/user-and-pass-auth) — credentials for each sub-account
* [**IP Whitelisting**](https://docs.rapidproxy.io/proxies/dynamic-residential-proxy/get-proxy/api/ip-whitelisting) — allowlisted source IP authentication

You’ll see examples using both methods where applicable.

> Note: Replace placeholder values like `YOUR_PROXY_HOST`, `YOUR_PORT`, `YOUR_USERNAME`, `YOUR_PASSWORD` with real values from your Rapidproxy dashboard.

***

### 2. cURL Examples

#### Dynamic Residential Proxy — Username & Password

```
curl -x http://YOUR_USERNAME:YOUR_PASSWORD@YOUR_PROXY_HOST:YOUR_PORT https://example.com
```

#### Dynamic Residential Proxy — IP Whitelist (no credentials)

```
curl -x http://YOUR_PROXY_HOST:YOUR_PORT https://example.com
```

*(Ensure your current IP is whitelisted before using this request.)*

#### Static Residential Proxy

```
curl -x http://YOUR_USERNAME:YOUR_PASSWORD@YOUR_STATIC_IP:YOUR_PORT https://example.com
```

#### Unlimited Residential Proxies

```
curl -x "Servers" -U "Username_res_EU_sid_*******_time_10:Password"http://ipinfo.io
```

***

### 3. Python Example (requests library)

#### With Username & Password Auth

```
import requests

proxy = "http://YOUR_USERNAME:YOUR_PASSWORD@YOUR_PROXY_HOST:YOUR_PORT"

proxies = {
    "http": proxy,
    "https": proxy
}

url = "https://example.com"
response = requests.get(url, proxies=proxies)
print(response.text)
```

#### With IP Whitelisting Only

```
import requests

proxy = "http://YOUR_PROXY_HOST:YOUR_PORT"

proxies = {
    "http": proxy,
    "https": proxy
}

response = requests.get("https://example.com", proxies=proxies)
print(response.text)
```

#### Unlimited Residential Proxies

```
import requests
if __name__ == '__main__':
proxyip = "http://USERNAME_res_EU_sid_*********_time_10:Password@Servers
url = "http://ipinfo.io"
proxies = {
'http': proxyip,
}
data = requests.get(url=url, proxies=proxies)
print(data.text)
```

***

### 4. Node.js Example (axios)

#### With Username & Password Auth

```
import axios from "axios";

const proxy = {
  host: "YOUR_PROXY_HOST",
  port: YOUR_PORT,
  auth: {
    username: "YOUR_USERNAME",
    password: "YOUR_PASSWORD"
  }
};

axios.get("https://example.com", { proxy })
  .then(res => console.log(res.data))
  .catch(err => console.error(err));
```

#### With IP Whitelisting Only

```
import axios from "axios";

const proxy = {
  host: "YOUR_PROXY_HOST",
  port: YOUR_PORT
};

axios.get("https://example.com", { proxy })
  .then(res => console.log(res.data))
  .catch(err => console.error(err));
```

#### Unlimited Residential Proxies

```
import requests
if __name__ == '__main__':
proxyip = "http://USERNAME_res_EU_sid_*********_time_10:Password@Servers
url = "http://ipinfo.io"
proxies = {
'http': proxyip,
}
data = requests.get(url=url, proxies=proxies)
print(data.text)
```

***

### 5. Puppeteer Example (Headless Browser)

#### With Username & Password Auth

```
const puppeteer = require("puppeteer");

(async () => {
  const browser = await puppeteer.launch({
    args: [
      "--proxy-server=YOUR_PROXY_HOST:YOUR_PORT"
    ]
  });

  const page = await browser.newPage();
  await page.authenticate({
    username: "YOUR_USERNAME",
    password: "YOUR_PASSWORD"
  });

  await page.goto("https://example.com");
  console.log(await page.content());
  await browser.close();
})();
```

***

### 6. Java Example (Apache HttpClient)

#### With Username & Password Auth

```
HttpHost proxy = new HttpHost("YOUR_PROXY_HOST", YOUR_PORT);

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
    new AuthScope(proxy),
    new UsernamePasswordCredentials("YOUR_USERNAME", "YOUR_PASSWORD")
);

CloseableHttpClient client = HttpClients.custom()
    .setDefaultCredentialsProvider(credsProvider)
    .build();

HttpGet request = new HttpGet("https://example.com");
HttpResponse response = client.execute(proxy, request);

System.out.println(EntityUtils.toString(response.getEntity()));
```

#### Unlimited Residential Proxies

```
public class Main {
    public static void main(String[] args) throws Exception {
        try {
            String proxyHost = "Server";
            int proxyPort = ****;
            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
            String username = "Username_res_GLOBAL_sid_********_time_10";
            String password = "Password";
            String credentials = username + ":" + password;
            URL url = new URL("http://ipinfo.io");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Proxy-Authorization", "Basic " + Base64.getEncoder().encodeToString(credentials.getBytes()));
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            StringBuilder response = new StringBuilder();
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
            System.out.println((response.toString()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

```

***

### **7.** Unlimited Residential Proxies - Additional Code Examples

#### PHP

```
Copy
$ch = curl_init();
curl_setopt($ch, CURLOPT_PROXY, "Serve" );
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "Username_res_GLOBAL_sid_********_time_10:Password");
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_URL, 'http://ipinfo.io');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);
curl_close($ch);
echo $result;

```

#### GO

```
package main
import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"os"
)
func main() {
	proxyURL, _ := url.Parse(" http://Username_res_GLOBAL_sid_********_time_10:Password@Server)
	proxy := http.ProxyURL(proxyURL)
	transport := &http.Transport{
		Proxy: proxy,
	}
	client := &http.Client{
		Transport: transport,
	}
	targetURL := "http://ipinfo.io"

	resp, err := client.Get(targetURL)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error fetching from", targetURL, ":", err)
		os.Exit(1)
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error reading response body:", err)
		os.Exit(1)
	}

	fmt.Println(string(body))
}

```

#### C\#

```
// See https://aka.ms/new-console-template for more information
using System.Net;
using System.Threading;

var handler = new HttpClientHandler
{
    UseProxy = true
};
var proxy = new WebProxy("http://Server");
var proxyUsername = "Username_res_GLOBAL_sid_********_time_10";
var proxyPass = "Password";
proxy.Credentials = new NetworkCredential(proxyUsername, proxyPass);
handler.Proxy = proxy;
var httpClient = new HttpClient(handler);

httpClient.Timeout = TimeSpan.FromSeconds(15);

var task = httpClient.GetStringAsync("http://ipinfo.io/json");
task.Wait();
Console.WriteLine(task.Result);

```

***

### 8. Tips for Using Proxies in Code

#### Protocol Support

* HTTP and HTTPS are both supported
* SOCKS5 can be used if your client supports the protocol

#### Sticky Sessions (Dynamic Proxies)

If you configured a **sticky session** when generating proxy credentials:

* Each request within the session will use the **same IP**
* Useful for login, form submission, and session-based automation

#### IP Whitelist

If using IP whitelisting:

* Confirm the source IP of your application or server is added to the whitelist
* Requests from non-whitelisted IPs will be blocked

***

### 9. Troubleshooting

If your code receives proxy errors:

* Double-check proxy host/port values
* Ensure credentials are correct (for username/password authentication)
* Verify your IP is whitelisted (if applicable)
* Check that your tool/client supports the proxy protocol you are using

If issues persist, contact support:

* **Online live chat on the Rapidproxy website**
* **Email:** `support@rapidproxy.io`

***

### 10. Security Notes

* Never share credentials publicly
* Store proxy usernames & passwords in secure configuration or environment variables
* Rotate credentials if compromised
