I am working with PHP/CURL and would like to send POST data to my phantomjs script, by setting the postfields array below:
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFieldArray);
curl_setopt($ch, CURLOPT_URL, $url);
$output = curl_exec($ch);
The problem is I don't know how to parse a POST request inside the phantomjs script. I am using the webserver module to expose the script.
I suspect https://github.com/benfoxall/phantomjs-webserver-example/blob/master/server.js may have the answer, but I don't know enough javascript to tell whether post variables are being parsed:
var service = server.listen(port, function(request, response) {
if(request.method == 'POST' && request.post.url){
var url = request.post.url;
request_page(url, function(properties, imageuri){
response.statusCode = 200;
response.write(JSON.stringify(properties));
response.write("\n");
response.write(imageuri);
response.close();
})
Can someone show me how to parse a POST request here?