tikiwiki/packages/tiki-pkg-casperjs/jakoch/phantomjs/examples/postjson.js
2023-11-20 20:52:04 +00:00

20 lines
472 B
JavaScript
Executable File

// Example using HTTP POST operation
"use strict";
var page = require('webpage').create(),
server = 'http://posttestserver.com/post.php?dump',
data = '{"universe": "expanding", "answer": 42}';
var headers = {
"Content-Type": "application/json"
}
page.open(server, 'post', data, headers, function (status) {
if (status !== 'success') {
console.log('Unable to post!');
} else {
console.log(page.content);
}
phantom.exit();
});