这很好(当我输入凭据时)
This works fine ( when I put my credentials in )
我尝试了以下代码:
import axios from "axios";
async function testApi() {
try {
const b = await axios.post("https://oauth.nzpost.co.nz/as/token.oauth2", {
client_id: "xxxxxxxxxxxxxxxxxxxxxxxxx",
client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
grant_type: "client_credentials"
});
} catch (error) {
console.log(error);
}
}
testApi();
这失败.错误400.必须为grant_type.我已经尝试将其作为参数包含在data:json块中.我无法弄清楚!
This fails. Error 400 . grant_type is required. I have tried putting it as a parameter , enclosing within a data: json block . I can't figure this out!
推荐答案
我修复了它,我需要将值放在参数中
I fixed it , I needed to put the values in parameters
import axios from "axios";
async function testApi() {
try {
const b = await axios.post("https://oauth.nzpost.co.nz/as/token.oauth2",
params: {
client_id: "xxxxxxxxxxxxxxxxxxxxxxxxx",
client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
grant_type: "client_credentials"
});
} catch (error) {
console.log(error);
}
}
testApi();
这篇关于如何将cURL转换为axios请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!