Http post usage


#1

I tried feth and http. I can not POST. The PHP print_r () function does not print.
The example in the document does not work either.


        exports.pageLoaded = function() {

        var http = require("http");

            var result;

            http.request({
                url: "https://httpbin.org/post",
                method: "POST",
                headers: { "Content-Type": "application/json" },
                content: JSON.stringify({ MyVariableOne: "ValueOne", MyVariableTwo: "ValueTwo" })
            }).then(function (response) {
                 result = response.content.toJSON();
                 console.log(result.MyVariableOne);
            }, function (e) {
                  console.log("Error occurred " + e);
            });


        }; 

Could you tell me how my PHP code should be and why not?

Here, “Improve this document” and “Demo Source” links do not work. My God!
fetch.md

SOLVED

  var url  = 'http://10.0.3.2';
   var data = "x=" + "aaa";
   fetch(url, { method: 'POST', body: data })
   .then(function (response) {
   return response.json();
   })
   .then(function (body) {   
   console.log(body.veri  )
   });

///////

 $array["veri"] = $_POST['x'];
 echo json_encode($array);



#2

Tks… for some reason the content returned in the JSON.stringify({}) at body, is diferent from the expected format.

I’ve tried your idea and it works!

Tks!