POST & PUT Requests
WebScrapingAPI is not limited to GET requests. You can now easily scrape the internet by sending POST or PUT requests as well.
Currently in BETA version, the POST and PUT requests are sent to the same base API URL. The only requirement for such requests is to pass the data (payload) alongside your request.
As you will see in the examples below, the only difference between the POST and the PUT requests is the HTTP method. Apart from that, both requests are similar with respect to the endpoint and parameters passed.
post
https://api.webscrapingapi.com/v1
?api_key=<YOUR_API_KEY>&url=https://httpbin.org/post
Basic POST Request
cURL
NodeJS
Python
php
Golang
Java
.NET
Ruby
curl --request POST --url "https://api.webscrapingapi.com/v1?api_key=<YOUR_API_KEY>&url=https%3A%2F%2Fhttpbin.org%2Fpost" --data "{
"foo": "bar"
}"
const http = require("https");
const options = {
"method": "GET",
"hostname": "api.webscrapingapi.com",
"port": null,
"path": "/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fget&proxy_type=datacenter",
"headers": {}
};
const req = http.request(options, function (res) {
const chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
import requests
API_KEY = '<YOUR_API_KEY>'
SCRAPER_URL = 'https://api.webscrapingapi.com/v1'
TARGET_URL = 'https://httpbin.org/post'
PARAMS = {
"api_key":API_KEY,
"url": TARGET_URL,
}
HEADERS = {
'WSA-Content-Type':'application/json',
'WSA-Accept':'application/json'
}
DATA = {
"query":"\\n mutation {\\n createCartItem(\\n \\n menuItemId: \\\ '105097698\\\'\\n …\\n \)} \""
}
response = requests.post(SCRAPER_URL, data=DATA, params=PARAMS, headers=HEADERS)
print(response.text)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.webscrapingapi.com/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fpost",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n \"foo\": \"bar\"\n}",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.webscrapingapi.com/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fpost"
payload := strings.NewReader("{\n \"foo\": \"bar\"\n}")
req, _ := http.NewRequest("POST", url, payload)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
HttpResponse<String> response = Unirest.post("https://api.webscrapingapi.com/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fpost")
.body("{\n \"foo\": \"bar\"\n}")
.asString();
var client = new RestClient("https://api.webscrapingapi.com/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fpost");
var request = new RestRequest(Method.POST);
request.AddParameter("undefined", "{\n \"foo\": \"bar\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://api.webscrapingapi.com/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fpost")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request.body = "{\n \"foo\": \"bar\"\n}"
response = http.request(request)
puts response.read_body
put
https://api.webscrapingapi.com/v1
?api_key=<YOUR_API_KEY>&url=https://httpbin.org/put
Basic PUT Request
cURL
NodeJS
Python
php
Golang
Java
.NET
Ruby
curl --request POST --url "https://api.webscrapingapi.com/v1?api_key=<YOUR_API_KEY>&url=https%3A%2F%2Fhttpbin.org%2Fput" --data "{
"foo": "bar"
}"
const http = require("https");
const options = {
"method": "PUT",
"hostname": "api.webscrapingapi.com",
"port": null,
"path": "/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fput",
"headers": {}
};
const req = http.request(options, function (res) {
const chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write("{\n \"foo\": \"bar\"\n}");
req.end();
import requests
API_KEY = '<YOUR_API_KEY>'
SCRAPER_URL = 'https://api.webscrapingapi.com/v1'
TARGET_URL = 'https://httpbin.org/put'
PARAMS = {
"api_key":API_KEY,
"url": TARGET_URL,
}
HEADERS = {
'WSA-Content-Type':'application/json',
'WSA-Accept':'application/json'
}
DATA = {
"query":"\\n mutation {\\n createCartItem(\\n \\n menuItemId: \\\ '105097698\\\'\\n …\\n \)} \""
}
response = requests.put(SCRAPER_URL, data=DATA, params=PARAMS, headers=HEADERS)
print(response.text)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.webscrapingapi.com/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fput",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\n \"foo\": \"bar\"\n}",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.webscrapingapi.com/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fput"
payload := strings.NewReader("{\n \"foo\": \"bar\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
HttpResponse<String> response = Unirest.put("https://api.webscrapingapi.com/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fput")
.body("{\n \"foo\": \"bar\"\n}")
.asString();
var client = new RestClient("https://api.webscrapingapi.com/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fput");
var request = new RestRequest(Method.PUT);
request.AddParameter("undefined", "{\n \"foo\": \"bar\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://api.webscrapingapi.com/v1?api_key=%7B%7Bapi_key%7D%7D&url=https%3A%2F%2Fhttpbin.org%2Fput")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Put.new(url)
request.body = "{\n \"foo\": \"bar\"\n}"
response = http.request(request)
puts response.read_body
Last modified 6mo ago