POST Request
You can also send a POST request through Scrapingdog API along with the headers and the data you want to submit to another API or a form.
Usage
url -d 'foo=bar' \
-X POST \
"https://api.scrapingdog.com/scrape?api_key=5e5a97e5b1ca5b194f42da86c5e27dd646&url=http://httpbin.org/anything"
import requests
url = "https://api.scrapingdog.com/scrape?api_key=5e5a97e5b1ca5b194f42da86c5e27dd646&url=http://httpbin.org/anything"
data = {"foo": "bar"}
response = requests.post(url, data=data)
print(response.text)
const axios = require('axios');
const url = 'https://api.scrapingdog.com/scrape?api_key=5e5a97e5b1ca5b194f42da86c5e27dd646&url=http://httpbin.org/anything';
const data = { foo: 'bar' };
axios.post(url, data)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error(error);
});
<?php
$api_key = '5e5a97e5b1ca5b194f42da86c5e27dd646';
$url = 'http://httpbin.org/anything';
$data = array('foo' => 'bar');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.scrapingdog.com/scrape?api_key=' . $api_key . '&url=' . $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'cURL error: ' . curl_error($ch);
}
curl_close($ch);
echo $response;
?>
require 'net/http'
require 'uri'
api_key = '5e5a97e5b1ca5b194f42da86c5e27dd646'
url = 'http://httpbin.org/anything'
uri = URI.parse("https://api.scrapingdog.com/scrape?api_key=#{api_key}&url=#{url}")
data = { 'foo' => 'bar' }
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(data)
response = http.request(request)
puts response.body
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) {
try {
String apiKey = "5e5a97e5b1ca5b194f42da86c5e27dd646";
String url = "http://httpbin.org/anything";
URL apiUrl = new URL("https://api.scrapingdog.com/scrape?api_key=" + apiKey + "&url=" + url);
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
connection.setRequestMethod("POST");
Map<String, String> parameters = new HashMap<>();
parameters.put("foo", "bar");
connection.setDoOutput(true);
OutputStream os = connection.getOutputStream();
os.write(getParamsString(parameters).getBytes());
os.flush();
os.close();
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
// Request was successful
// Process the response here
} else {
// Request failed
System.out.println("Request failed with response code: " + responseCode);
}
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
private static String getParamsString(Map<String, String> params) {
StringBuilder result = new StringBuilder();
for (Map.Entry<String, String> entry : params.entrySet()) {
if (result.length() > 0) {
result.append("&");
}
result.append(entry.getKey());
result.append("=");
result.append(entry.getValue());
}
return result.toString();
}
}
Last updated