Reputation: 499
These are what the headers look like in Insomnia:
On the left are request headers and on the right are response headers. And I wrote following code for this:
const https = require('https');
const options = {
hostname: 'https://www.sahibinden.com/',
path: '/get',
headers: {
"X-Origin-DC":"gytp",
"Cache-Control": "max-age=0",
"X-Forwarded-For": "103.255.4.53",
"X-Client-SrcPort": "45244",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"X-Forwarded-Proto": "https",
"X-TLS-Version": "771",
"Upgrade-Insecure-Requests": "1",
"ISTL-REFERER":"https://www.sahibinden.com/"
}
}
https.get(options, (response) => {
var result = ''
console.log(response.headers);
response.on('data', function (chunk) {
result += chunk;
});
response.on('end', function () {
console.log(result);
});
});
It gives me following error:
events.js:287
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND https://www.sahibinden.com/
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:64:26)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (_http_client.js:426:9)
at TLSSocket.emit (events.js:310:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'https://www.sahibinden.com/'
}
How do I fix this?
Upvotes: 0
Views: 552
Reputation: 331
Change the value of hostname
in options
to www.sahibinden.com
(remove https://
and slash (/
) at the end. Also, change path: '/get'
to method: 'get'
, you probably meant to use method
instead of path
. path
is used for specifying the rest of the URL path after the host URL.
You can also specify port
in options as 443
(as a replacement for https
), but since you're using https
module, port: 443
is the default.
Upvotes: 1