2

I have a very simple request, but warn me Parse Error:

var http = require('http');
var url = require('url');

var opts = {
    host: 'www.appletreebooks.com',
    path: 'www.appletreebooks.com/appIndex.php?c=eshop&m=get_hot_new_book_list&per_page=1&devid=c4c8874d16d84cde8fc7b9037ad8e26465bd1560&uid=1&ln=sn',
}

var req = http.request(opts, function (res) {
    res.setEncoding('utf8');
    var data = ""
    res.on('data', function(d) {
        data += d;
    })

    res.on('end', function() {
        console.log(data);
    })
})

req.on('error', function(e) {
  console.log('problem with request: ' + e.message);
});

req.end();

But the response me Parse Error

What's wrong with my code? How can I get the data correctly?

1 Answer 1

3

Your opts.path should not include the hostname.

var opts = {
    host: 'www.appletreebooks.com',
    path: '/appIndex.php?c=eshop&m=get_hot_new_book_list&per_page=1&devid=c4c8874d16d84cde8fc7b9037ad8e26465bd1560&uid=1&ln=sn',
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.