我正在使用 chrome 的 POSTMAN 扩展,并尝试向 phantomjs 发送发布请求 我已通过设置邮递员,如随附的屏幕截图所示,设法将发布请求发送到 phantomjs 服务器脚本
我的 phantomjs 脚本如下:
// import the webserver module, and create a server
var server = require('webserver').create();
var port = require('system').env.PORT || 7788;
console.log("Start Application");
console.log("Listen port " + port);
// Create serever and listen port
server.listen(port, function(request, response) {
console.log("request method: ", request.method); // request.method POST or GET
if(request.method == 'POST' ){
console.log("POST params should be next: ");
console.log(request.headers);
code = response.statusCode = 200;
response.write(code);
response.close();
}
});
当我在命令行运行 phantomjs 时,输出如下:
$ phantomjs.exe myscript.js
Start Application
Listen port 7788
null
request method: POST
POST params should be next:
[object Object]
POST params: 1=bill&2=dave
所以,它似乎确实有效。我现在的问题是如何将帖子正文解析为变量,以便我可以在脚本的其余部分中访问它。