# Anfrage erhalten
In diesem Abschnitt erläutern wir das Verfahren zum Versenden von GET-Anfragen mithilfe des Smart Proxy-Dienstes von Crawlbase. Dies stellt einen einfachen Befehl zum Ausführen einer GET-Anfrage über den Smart Proxy dar.
- curl
- ruby
- node
- php
- python
- go
curl -x "http://[email protected]:8012" -k "http://httpbin.org/ip"
require 'net/http'
require 'openssl'
proxy_host = 'smartproxy.crawlbase.com'
proxy_port = 8012
proxy_user = '_USER_TOKEN_'
uri = URI('http://httpbin.org/ip')
# Create a Net::HTTP object with the appropriate proxy settings
http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user)
# If the request is HTTPS, skip SSL verification
http.use_ssl = uri.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
# Perform the request and print the status and body
res = http.get(uri.request_uri)
puts res.code, res.message, res.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,
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: 8012,
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",
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
proxy_url = "http://_USER_TOKEN_:@smartproxy.crawlbase.com:8012"
proxies = {"http": proxy_url, "https": proxy_url}
response = requests.get(url="http://httpbin.org/ip", proxies=proxies, verify=False)
print('Response Code: ', response.status_code)
print('Response Body: ', response.content)
package main
import (
"fmt"
"crypto/tls"
"io/ioutil"
"net/http"
"net/url"
)
func main() {
// Create the proxy URL
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
}
// 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))
}