此页面在纯空 html/body 标记中显示 JSON。例如:
<html>
<body>
**JSON DATA ***
</body>
</html>
我可以在浏览器中正常访问该页面。但是,当我发送请求时,它说我的凭据无效(响应错误几乎在标题中)。这是代码
import dotenv = require('dotenv');
dotenv.config({ path: '../logins.env' });
import rp = require('request-promise');
const jsonUrl = `http://availability.emodal.com/ImportAvailability/GetContainerInfoList?sgrdModel=%7B%22searchtext%22:%22%22,%22page%22:1,%22pageSize%22:280,%22sortBy%22:%221%22,%22sortDirection%22:%22asc%22,%22sortColumns%22:%22%22%7D`;
const authOpts = {
uri: jsonUrl,
auth: {
user: process.env.EMODAL_id,
pass: process.env.EMODAL_pw,
sendImmediately: false
},
method: 'get'
}
rp(authOpts)
.then(resp => {
console.log(resp);
}).catch(err => { throw Error(err)});
我试着改变周围的一切。就像添加标题,或者放置 json: true,或者将 sendImmediately 更改为 true。没有任何效果。我不明白什么或我做错了什么?
谢谢