jquery - Codeception - POST raw JSON string -
jquery - Codeception - POST raw JSON string -
i sending next request using jquery
var url = 'http://site.local/api/package/create'; var info = { "command": "package", "commandparameters": { "options": [ { "a": true } ], "parameters": { "node_id": 1111, "node_name": "node name" } } } $.ajax({ url: url, type: "post", data: json.stringify(data), contenttype: "application/json", success: function (a, b, c) { // response } }); also doing similar using postman (chrome plugin)
post content-type: application/json payload: { "command": "package", "commandparameters": { "options": [ { "a": true } ], "parameters": { "node_id": 1111, "node_name": "node name" } } } it intended send raw json string server, rather have jquery convert post data. how perform same in codeception, can't see in documentation, see following..
$i->sendajaxpostrequest('/updatesettings', array('notifications' => true)); so guess want create post request in codeception, while attaching json in body of request?
the encodeapplicationjson function in codeception/src/codeception/module/rest.php checks if header "content-type" , value "application/json" exist.
if set returns json_encode($parameters) string want, end doing this...
$i->havehttpheader('content-type', 'application/json'); $i->sendpost('api/package/create', [ 'command' => 'package', 'commandparameters' => [ 'options' => [], 'arguments' => [] ] ]); $i->canseeresponsecodeis(200); $i->seeresponseisjson(); some info on difference between sendpost , sendajaxpostrequest
http://phptest.club/t/what-is-the-difference-between-sendpost-and-sendajaxpostrequest/212#post_2
jquery json rest codeception postman
Comments
Post a Comment