admin管理员组文章数量:1427134
I have some code that is trying to get a JSON result from the Soundcloud API.
I registered an app, got the client id and such, and I'm trying to make a call like this:
var querystring = require('querystring');
var http = require('http');
var addr = '.json?url=;client_id=XXXXX';
var options = {
hostname: "api.soundcloud",
path: "/resolve.json?url=;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);
});
});
This produces a result that looks like this:
{"status":"302 - Found","location":".json?client_id=xxxx"}
When I use the same URL in Chrome, I get the proper JSON info. How do I properly make this call from server side script?
I have some code that is trying to get a JSON result from the Soundcloud API.
I registered an app, got the client id and such, and I'm trying to make a call like this:
var querystring = require('querystring');
var http = require('http');
var addr = 'http://api.soundcloud./resolve.json?url=http://soundcloud./matas/hobnotropic&client_id=XXXXX';
var options = {
hostname: "api.soundcloud.",
path: "/resolve.json?url=http://soundcloud./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);
});
});
This produces a result that looks like this:
{"status":"302 - Found","location":"https://api.soundcloud./tracks/49931.json?client_id=xxxx"}
When I use the same URL in Chrome, I get the proper JSON info. How do I properly make this call from server side script?
Share Improve this question asked Sep 22, 2014 at 0:26 opticonopticon 3,6145 gold badges41 silver badges68 bronze badges2 Answers
Reset to default 5The built-in http client does not handle redirects. However request does and has many other features the built-in client does not support out of the box.
Today I updated my own NodeJS Api-Wrapper Package for Soundcloud, which can be found here: https://www.npmjs./package/soundcloud-nodejs-api-wrapper
It does server side API munication, which includes data modification. No user popup window and redirect url is needed.
I did not found yet any other package having support for this in NodeJS.
本文标签: javascriptMaking HTTP requests from server sideStack Overflow
版权声明:本文标题:javascript - Making HTTP requests from server side - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745485325a2660355.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论