我正在使用以下代码
var http = require('http'),
url = require('url');
function handle_incoming_request (req, res) {
console.log('Incoming request: (' + req.method + ') ' + req.url);
req.parsed_url = url.parse(req.url, true);
console.log(req.parsed_url);
}
var server = http.createServer(handle_incoming_request);
server.listen(8080);
现在我curl
下面
curl -i -X GET http://localhost:8080/albums/italy2012.json?page=0&page_size=20
然后我在节点控制台
下面Incoming request: (GET) /albums/italy2012.json?page=0
{ protocol: null,
slashes: null,
auth: null,
host: null,
port: null,
hostname: null,
hash: null,
search: '?page=0',
query: { page: '0' },
pathname: '/albums/italy2012.json',
path: '/albums/italy2012.json?page=0',
href: '/albums/italy2012.json?page=0' }
正如你在第一行看到的那样,网址是一半。它省略了&page_size=20
为什么以及如何解决此问题?
答案 0 :(得分:4)
问题在于你如何通过CURL发布,你需要引用URL,否则&符号会将CURL设置为后台进程
curl -i -X GET "http://localhost:8080/albums/italy2012.json?page=0&page_size=20"