-
Hi folks. I am doing successfully get requests on a foreign API with the following plain Request-flow (I've removed error handling for this example): function request(options) {
return new Promise((resolve, reject) => {
const req = https.request(options.url, {
...options,
}, (res) => {
res.on('data', d => {
resolve(d);
});
req.end();
});
}); I am including an oAuth-Authorization-header which looks like this: const authHeader = { authorization: 'OAuth oauth_consumer_key="xxxxxx-xxxx-xxxxx-xxxx-xxxxxxxx", oauth_nonce="xxxxxxxxxx", oauth_signature="xxxxxxxxxxxxxxxx%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1612448019", oauth_token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", oauth_version="1.0"' }; Calling the endpoint: const resultString = await request({
url: "https://api.mygarmin.com/",
method: "GET",
headers: authHeader,
}); I expext a JSON string, so I do: const jsonResult = JSON.parse(resultString); This works as expect. But of course is not ideal. I would like to use Got and using the retry mechanism and so on. When I try the same with Got I am receiving and HTTP 415 Media Type Unssuproted from the API. I've tried those settings: const response = await got(url, {
timeout: 10000,
retry: 2,
headers: {
...authHeader,
accept: "application/json",
},
responseType: 'json',
}); const response = await got(url, {
timeout: 10000,
retry: 2,
headers: authHeader,
responseType: 'json',
}); const response = await got(url, {
timeout: 10000,
retry: 2,
headers: authHeader,
}).json(); Everything of those is returning a 415. Questions:
... Checklist
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I cannot reproduce this, but you can use Wireshark to inspect what are the differences in the requests. |
Beta Was this translation helpful? Give feedback.
I cannot reproduce this, but you can use Wireshark to inspect what are the differences in the requests.