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 badges
Add a ment  | 

2 Answers 2

Reset to default 5

The 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