IBM Watson Retrieve and Rank服务的API使用基本认证。方法有几种,其中之一 - 使用模块request
:
var url = "https://gateway.watsonplatform.net/retrieve-and-rank/api/v1/solr_clusters/sc1ca23733_faa8_49ce_b3b6_dc3e193264c6/solr/example_collection/select?q=what%20is%20the%20basic%20mechanism%20of%20the%20transonic%20aileron%20buzz&wt=json&fl=id,title"
request.get('http://some.server.com/', {
auth: {
user: 'username',
pass: 'password',
sendImmediately: false
},
json: true
}, function(error, response, body) {
console.log('Found: ', body.response.numFound);
});
或
var username = 'username',
password = 'password',
url = "https://" + user + ":" + password + "@" + "gateway.watsonplatform.net/retrieve-and-rank/api/v1/solr_clusters/sc1ca23733_faa8_49ce_b3b6_dc3e193264c6/solr/example_collection/select?q=what%20is%20the%20basic%20mechanism%20of%20the%20transonic%20aileron%20buzz&wt=json&fl=id,title"
request({url: url, json: true}, function (error, response, body) {
console.log('Found: ', body.response.numFound);
});
我会从使用请求模块(https://www.npmjs.com/package/request)开始。只需使用您的用户名和密码从节点调用给定的url即可 – Markus