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:
parent
bda8838698
commit
300f28cc5d
13
examples/postjson.coffee
Normal file
13
examples/postjson.coffee
Normal 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
18
examples/postjson.js
Normal 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();
|
||||
});
|
Loading…
Reference in New Issue
Block a user