Adding Headers

Headers can be sent with any request, just add the field headers to your json request.


Example headers to be added to request

{
"url": "https://news.ycombinator.com/",
"headers": {
"Referer": "http://en.wikipedia.org/wiki/Main_Page"
}
}

Example request with headers

const https = require('https');
const TROVE_KEY = '<YOUR_TROVE_KEY>';
const TROVE_API = `https://api.usetrove.io/v1/fetch/browser?key=${TROVE_KEY}`;
function handleResponse(response) {
response.setEncoding('utf8');
response.on('data', function (data) {
const htmlResponse = data;
console.log(htmlResponse);
});
}
function sendRequest(postBody) {
const url = new URL(TROVE_API);
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
};
const request = https.request(url, requestOptions, handleResponse);
request.write(JSON.stringify(postBody));
request.end();
}
sendRequest({
url: 'https://google.com/search?q=social%20media%20marketing',
headers: {
Referer: 'http://en.wikipedia.org/wiki/Main_Page',
},
});
// <!DOCTYPE html>
// <html itemscope="" itemtype="http://schema.org/SearchResultsPage" lang="en">
// <head>
// <meta
// content="/images/branding/googleg/1x/googleg_standard_color_128dp.png"
// itemprop="image"
// />
// <meta content="origin" name="referrer" />
// <title>social media marketing - Google Search</title>
// <meta
// content="At65Ued/IKGjC1CHbimm0Lp+lkdFLAxYwLJcFtCOYfet7yt3CzeAxdYQzUwWr6pf1Im3ATkD/5XFcTJpyN5HXw8AAABTeyJvcmlnaW4iOiJodHRwczovL3d3dy5nb29nbGUuY29tOjQ0MyIsImZlYXR1cmUiOiJUcnVzdFRva2VucyIsImV4cGlyeSI6MTYwMjUyNzU0MX0="
// http-equiv="origin-trial"
// />
// ...more html