node.js请求js与curl相比失败
node.js requestjs fails vs curl
我们试图使用requestjs调用基于JSON的API,但我们从服务器收到了一个错误。
request.get({
url: 'https://api.myapi.com',
timeout: 120000,
headers: {
username: 'myuser',
password: 'mypassword'
}
}, function (err, result) {
...
}
)
错误:
java.lang.IndexOutOfBoundsException: Index: 0
java.util.Collections$EmptyList.get(Collections.java:4454)
com.itemmaster.api.rest.svc.authentication.OpenSSOUserAuthServiceImpl.authenticate(OpenSSOUserAuthServiceImpl.java:159)
com.itemmaster.api.rest.profiler.SecurityProfiler.profile(SecurityProfiler.java:58)
当使用curl运行相同的调用时,返回没有任何问题。
curl --header "username:myuser" --header "password:mypassword" 'https://api.myapi.com'
如果curl命令使用您提供的语法,那么以下代码应该在node.js.中工作
var request = require('request');
var headers = {
'username': 'myuser',
'password': 'mypassword'
};
var options = {
url: 'https://api.myapi.com',
headers: headers
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
相关文章:
- PHP和JS脚本的奇怪问题,在我刷新页面之前第一次失败
- 使用Office.js在Excel中将20000多个单元格写入表失败
- scrypt.js失败,N大于2^14
- 解析JS SDK登录到Node.JS中运行的解析服务器=失败
- JS:执行'失败;getComputedStyle'在'窗口':参数的类型不是'
- 使用Q节点模块时,Bluemix node.js应用程序部署失败
- fs.readFileSync()在express js应用程序中失败
- 如何允许Dropzone.js失败后重新提交文件上传
- JS失败,除非控制台打开
- 节点中的 CORS 问题.js失败
- Jenkins sonar build使用js失败
- 通过请求从代码中获取 Dropbox OAuth 令牌.js失败;等效卷曲工作
- 使用bootstrap-carousel.js失败
- 滚动到一个元素使用js失败在我的情况下
- 扩展sap.m.List给了我错误:加载'sap/m/items.js'失败
- 时间序列与plot .js失败,w/ fiddle
- 拉斐尔JS失败了
- 关键错误插入到MongoDB使用node.js失败的一些对象没有任何键包含一个点
- 添加自定义标记图片的传单 js 失败
- 在OS X 10.8.2上构建ember.js失败