# Obtenir une demande
Dans ce segment, nous détaillons la procédure d'envoi de requêtes GET en utilisant Crawlbase's Smart Proxy service. Ceci représente une commande simple pour exécuter une requête GET via le Smart Proxy.
- curl
- ruby
- node
- php
- python
- go
Using HTTPS (recommended):
curl -x "https://[email protected]:8013" -k "https://httpbin.org/ip"
Using HTTP alternative:
curl -x "http://[email protected]:8012" -k "https://httpbin.org/ip"
# Installation: gem install typhoeus
require 'typhoeus'
# HTTPS proxy (recommended)
proxy_url = "https://[email protected]:8013"
# HTTP proxy alternative:
# proxy_url = "http://[email protected]:8012"
request = Typhoeus::Request.new(
"https://httpbin.org/ip",
proxy: proxy_url,
ssl_verifypeer: false, # Disabled for hostname SSL inspection
ssl_verifyhost: 0 # Disables hostname verification
)
response = request.run
puts response.code, response.body
const http = require('http');
const https = require('https');
const crawlbaseToken = '_USER_TOKEN_';
const auth = `Basic ${Buffer.from(crawlbaseToken).toString('base64')}`;
// HTTP request
const httpRequest = http.request({
host: 'smartproxy.crawlbase.com',
port: 8012, // Use 8013 for HTTPS
path: 'http://httpbin.org/ip',
headers: {'Proxy-Authorization': auth},
}, res => {
res.setEncoding('utf8');
res.on('data', console.log);
});
httpRequest.on('error', console.error);
httpRequest.end();
// HTTPS request
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0; // Disable TLS/SSL verification
const httpsRequest = http.request({
host: 'smartproxy.crawlbase.com',
port: 8013, // HTTPS port
method: 'CONNECT',
path: 'httpbin.org:443',
headers: {'Proxy-Authorization': auth},
}, (res, socket) => {
if (res.statusCode === 200) {
https.get({
host: 'httpbin.org',
path: '/ip',
socket: socket, // Using the provided socket
agent: false, // Disable the default agent
}, res => {
res.setEncoding('utf8');
res.on('data', console.log);
});
}
});
httpsRequest.on('error', console.error);
httpsRequest.end();
<?php
// cURL initialization
$ch = curl_init('http://httpbin.org/ip');
// Configuring cURL options
$curlOptions = [
CURLOPT_PROXY => "http://[email protected]:8012", // Use https:// and port 8013 for HTTPS
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false
];
// Setting cURL options
curl_setopt_array($ch, $curlOptions);
// Execute request and capture response
$response = curl_exec($ch);
// Handle any error
if (curl_error($ch)) {
die('Error: "'.curl_error($ch).'" - Code: '.curl_errno($ch));
}
// Output HTTP Status Code and Response Body
echo 'HTTP Status Code: '.curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL;
echo 'Response Body: '.$response . PHP_EOL;
// Close cURL session
curl_close($ch);
?>
# pip install requests
import requests
from urllib3.exceptions import InsecureRequestWarning
# Suppress only the single warning from urllib3 needed.
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
# Choose either HTTP or HTTPS endpoint
proxy_url = "http://_USER_TOKEN_:@smartproxy.crawlbase.com:8012" # Use https:// and port 8013 for HTTPS
proxies = {
"http": proxy_url,
"https": proxy_url
}
try:
response = requests.get(
url="http://httpbin.org/ip",
proxies=proxies,
verify=False,
timeout=30
)
response.raise_for_status() # Raise an exception for bad status codes
print('Response Code:', response.status_code)
print('Response Body:', response.text)
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
package main
import (
"fmt"
"crypto/tls"
"io/ioutil"
"net/http"
"net/url"
)
func main() {
// Create the proxy URL (use https:// and port 8013 for HTTPS)
proxyURL, _ := url.Parse("http://[email protected]:8012")
// Create a Transport with the proxy and insecure TLS configuration
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
// Create an HTTP client with the Transport
client := &http.Client{Transport: transport}
// Send the request
resp, err := client.Get("https://httpbin.org/ip")
if err != nil {
fmt.Println("Failure : ", err)
return
}
defer resp.Body.Close()
// Read the response body
respBody, _ := ioutil.ReadAll(resp.Body)
// Display results
fmt.Println("response Status : ", resp.Status)
fmt.Println("response Headers : ", resp.Header)
fmt.Println("response Body : ", string(respBody))
}