Page 1 of 1

Server Code XHR2 won't send POST data

Posted: Fri Jan 11, 2019 9:39 pm
by Bryan Novak

Hi there,

I'm trying to setup a basic login process that connects to a separate server where the logins are stored. We're setting it up with PHP files to receive the communication, do the processing and send back a response. We've used this before in several Jquery projects on Appery, but we're trying to update the process for a new Ionic project.

We were trying to set it up to use Server Code to make the call and handle the response but we can't get it to send any of the POST information. I've confirmed that it is hitting the correct PHP file and can read GETs, but not POST. I've paired it way back to the basic snippet included in Appery out of the box and still get no response.

code
var url=" -- link to our php file --"

var XHRResponse = XHR2.send("POST", url, {
"parameters": {
"param1": "param1",
"param2": "param2"
},
"headers": {
"Content-Type": "application/json",
"header1": "header1",
"header2": "header2",
},
"body": {
"body1": "body1",
"body2": "body2",
}
});

Apperyio.response.success(XHRResponse.body, "application/json");
/code

And the response we get from the above

code
{
"status": "error caused by POST fail", // Custom error message -- means the expected POST fields had no data
"POSTed": "", // Displays all POST data
"GETed": "param1param2" // Displays all GET data
}
/code

I've also tried working from the other example off Appery's site here: https://maxkatz.org/2016/03/28/how-to... but that didn't work either. Really confused. Is there another way I'm supposed to send POST information with Server Code?


Server Code XHR2 won't send POST data

Posted: Mon Jan 14, 2019 8:44 am
by Serhii Kulibaba

Hello,

You can use API Express REST component for that: https://docs.appery.io/docs/apiexpres...

Could you run the same request from any REST client, e.g. Postman and provide us the screenshot with all request data and the response?


Server Code XHR2 won't send POST data

Posted: Tue Jan 15, 2019 5:10 pm
by Bryan Novak

Thanks for the suggestion on using Postman. I wound up switching to API Express, but the problem turned out to be the header - Content Type. I had it set for Json, but my PHP file was designed to handle Form Data. Had to change the Content Type to "x-www-form-urlencoded" for it to read properly.