【发布时间】:2018-07-02 15:24:05
【问题描述】:
我遇到了一个奇怪的问题。我正在测试一个 API,并在 Postman 中勾勒出我的请求。事实上,他们目前在那里工作得很好。
POST /authEndpoint
content-type: application/json
accept: application/json
cache-control: no-cache
postman-token: some-token
user-agent: PostmanRuntime/7.1.1
host: greatapi.com
accept-encoding: gzip, deflate
content-length: 68
{
"user": "user",
"password": "secret"
}
我得到了我想要的回应。现在我尝试在 JavaScript 中使用 Axios 重新创建这个请求。问题是,我得到的不是响应,而是读取 ECONNRESET。我相信我就像在 Postman 中一样勾勒出它,所以这很奇怪。这是我的 Axios 配置:
import AXIOS from 'axios';
const BASE_URL = 'https://greatapi.com';
const axios = AXIOS.create({
baseURL: BASE_URL,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
}
});
axios.post('/authEndpoint', {
'user': 'user',
'password': 'secret',
})
.then(response => console.log(response.data))
.catch(error => console.error(error.message));
具体回应是这样的:
read ECONNRESET
你有什么想法吗?
【问题讨论】:
标签: javascript http postman axios