1
1
mirror of https://github.com/ariya/phantomjs.git synced 2024-09-11 04:46:09 +03:00

Add example for how to post a json request to HTTP server

https://github.com/ariya/phantomjs/issues/11969
This commit is contained in:
Adrian Chung 2014-02-10 22:53:28 -05:00 committed by Ariya Hidayat
parent bda8838698
commit 300f28cc5d
2 changed files with 31 additions and 0 deletions

13
examples/postjson.coffee Normal file
View File

@ -0,0 +1,13 @@
# Example using HTTP POST operation
page = require("webpage").create()
server = "http://posttestserver.com/post.php?dump"
data = "{\"universe\": \"expanding\", \"answer\": 42}"
headers = "Content-Type": "application/json"
page.open server, "post", data, headers, (status) ->
if status isnt "success"
console.log "Unable to post!"
else
console.log page.content
phantom.exit()

18
examples/postjson.js Normal file
View File

@ -0,0 +1,18 @@
// Example using HTTP POST operation
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();
});