I am working on a project that talks with an API, my script is in nodeJS (it's a big project so I will give you a very simplified version)
Essentially when I do a PUT request to the API, with the postman, it works fine, When I do it with my Code: GET works great (so I know the URL is correct), but PUT doesn't work with my script, I get no errors on my console, and the API simple sends back the OK status, so I have no clues where it went wrong
Here is a very basic version of my script (that doesn't work either)
(I know the URL is correct)
PUT parameters:
{ method: 'PUT',
baseUrl: 'https://fusionrv.XXXX.XX/fusion/apiservice',
url:
'XXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXX',
qs:
{ auth:
'AUTH_KEY',
value: 1 },
headers: { 'content-type': 'application/json' } }
simple code (without the imports):
request(putParams, (err, res) => {
if (err) console.log(err);
data = JSON.parse(res.body)
console.log(data)
});
In Postman, I have the same baseURL and url, as well as the same params "auth" and "value", the body is set to "none", and headers are Content-type: application/json
.
The response (both in Postman and NodeJS):
{
"Status": "Success"
}
So does anyone know why it works with postman but not with the request module? I appreciate all of you!
原来问题出在API上,我需要执行POST请求并使用其他URL来访问它,这是一个非常奇怪的API。
添加用户代理作为标题的一部分
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.