Reputation: 15626
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?
Upvotes: 2
Views: 6272
Reputation: 161457
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',
}
Upvotes: 3