Page 2 of 2

Mapping inputs to service header

Posted: Mon Feb 26, 2018 9:38 pm
by Alan Smith

After quite a few more days I am still having issues with this.

I am trying to post to an external API, using application/x-www-form-urlencoded, and am dumping/echoing the posted variables on the server.

OK, so if I use postman to post to the same url as I do within the app, using these headers:

array(10) {
["Content-Length"]=
string(2) "25"
["Content-Type"]=
string(33) "application/x-www-form-urlencoded"
["Accept"]=
string(3) "/"
["Accept-Encoding"]=
string(13) "gzip, deflate"
["Cache-Control"]=
string(8) "no-cache"
["Connection"]=
string(10) "keep-alive"
["Cookie"]=
string(51) "ci_session=523c1e6349ba759c1e59afd5ce434b9bce4ffc7b"
["Host"]=
string(21) "dashboard.cmg-org.com"
["Postman-Token"]=
string(36) "7c072e87-e399-4a77-985f-e9acb4c43d5a"
["User-Agent"]=
string(20) "PostmanRuntime/6.4.1"
}

I get this response:

string(35) "{"email":"alans","password":"pass"}"

Which is what I expect to get.

BUT

When using the appery app, posting to the same URL, using these headers:

Accept:application/json, text/plain, /
Accept-Encoding:gzip, deflate, br
Accept-Language:en-GB,en-US;q=0.9,en;q=0.8
Connection:keep-alive
Content-Length:52
Content-Type:application/x-www-form-urlencoded
email:alans
Host:api.appery.io
Origin:https://appery.io
password:pass
Referer:https://appery.io/app/view/27ffc72a-2...
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36

I get this response:

string(30) "{"email":null,"password":null}"

The app is sending the data in the header, query string and via form data, as is shown in this image:

Image

But I cannot get to any of this data on the server, everything is blank, even though it is working via postman.

Can you see anything in the above which is not right and preventing this data being available on the server?

Please?


Mapping inputs to service header

Posted: Tue Feb 27, 2018 4:00 pm
by Serhii Kulibaba

Is it an API Express service? If so - please send us a screenshot of it's settings.


Mapping inputs to service header

Posted: Tue Feb 27, 2018 4:03 pm
by Alan Smith

No its server code:

var url = "url";

var XHRResponse = XHR2.send("POST", url, {
"parameters": {
"password": '',
"email": '',
},
"headers": {
"Email": '',
"Password": '',
},
"body": "Request body"
});

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


Mapping inputs to service header

Posted: Tue Feb 27, 2018 7:46 pm
by Alan Smith

If i setup the server code like this, with the variables hard coded, then it works and I receive the posted data on the server. (foo & bar)

var url = "https://dashboard.cmg-org.com/auth/token";
var email = "foo";
var password = "bar";

var XHRResponse = XHR2.send("POST", url, {
"parameters": {
"password": password,
"email": email,
},
"body": ""
});

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

So how do i set this up to receive the input from the app UI?


Mapping inputs to service header

Posted: Wed Feb 28, 2018 4:47 pm
by Serhii Kulibaba

Every parameter here is empty.
The Server Code has to be like:
prevar XHRResponse = XHR2.send("POST", url, {
"parameters": {
"password": request.get("password"),
"email": request.get("email"),
},
"headers": {
"Email": request.headers.email,
"Password": request.headers.password,
},
"body": "Request body"
});

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