我有一些代码试图从Soundcloud API获取JSON结果。从服务器端发出HTTP请求
我注册了一个应用程序,得到了客户ID和这样的,我试图做这样的呼吁:
var querystring = require('querystring');
var http = require('http');
var addr = 'http://api.soundcloud.com/resolve.json?url=http://soundcloud.com/matas/hobnotropic&client_id=XXXXX';
var options = {
hostname: "api.soundcloud.com",
path: "/resolve.json?url=http://soundcloud.com/matas/hobnotropic&client_id=XXXXXx",
method: "GET",
headers: {
"Content-Type": "application/json"
}
}
var request = http.get(options, function(response) {
response.setEncoding('utf8');
response.on('data', function(chunk) {
console.log(chunk);
});
});
这产生的结果是这样的:
{"status":"302 - Found","location":"https://api.soundcloud.com/tracks/49931.json?client_id=xxxx"}
当我在Chrome中使用相同的URL时,我得到正确的JSON信息。如何正确地从服务器端脚本进行此调用?
+1。一直使用它 – rossipedia 2014-09-22 00:31:44
奇怪的是,我试图让这个特殊功能工作时,广泛地使用请求并完全消隐。感谢提醒:) – opticon 2014-09-22 00:47:40