【发布时间】:2018-12-22 10:30:27
【问题描述】:
我在 zapier 中有一个代码:
var username = "username"
var password = "password"
var grant_type = "password"
var client_id = "id"
var ENDPOINT="someUrl"
var json = {
"grant_type": grant_type,
"username": username,
"password": password,
"client_id": client_id
};
var options={
method:"POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
payload:json
}
const result = await fetch(WAVITY_ENDPOINT,options)
const content = await result.json()
output={response:content}
但我总是收到未经授权的错误。我通过请求模块做同样的事情并且它有效。我认为 fetch 没有发送数据。任何帮助将不胜感激。在我的请求模块代码中,我有以下选项:
headers: {
connection: "Keep-Alive",
timeout: 5000
},
url: ENDPOINT,
method: 'POST',
formData: {
'grant_type': grant_type,
'username': username,
'password': password,
'client_id': client_id
}
注意:将 fetch 的标头更改为请求中的标头也不适合我。
【问题讨论】:
-
只想先做个小检查,确保您在 fetch 中使用的端点变量与第 5 行所述的变量相同(您在第 5 行声明了“ENDPOINT”,然后将其称为WAVITY_ENDPOINT)