我正在尝试使用js访问Codeship的API,但它在cURL中提供了代码
这是卷曲的
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" --user '<your email>:<your password>' https://api.codeship.com/v2/auth
我不确定如何传递参数或用户
这是api文档,如果您需要https://apidocs.codeship.com/v2
谢谢您的帮助。
答案 0 :(得分:0)
如果您在node.js
中询问如何执行此操作,下面是使用常用axios http-request library的示例:
const axios = require('axios');
async function sendRequest() {
const requestConfig = {
method: 'post',
url: 'https://api.codeship.com/v2/auth',
headers: {
'Content-Type': 'application/json'
},
auth: {
username: 'your-user',
password: 'your-password'
}
};
try {
const response = await axios(requestConfig);
console.log(JSON.stringify(response.data));
return response;
} catch (error) {
console.log(error);
}
}