POSTMAN 拡張機能を chrome で使用していて、phantomjs に投稿要求を送信しようとしています。添付のスクリーンショットのように postman を設定することで、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
だから、それはうまくいくようです。私の質問は、投稿本文を変数に解析する方法であるため、スクリプトの残りの部分でアクセスできます。