Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

Mapping inputs to service header

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?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Mapping inputs to service header

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

Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

Mapping inputs to service header

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");

Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

Mapping inputs to service header

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?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Mapping inputs to service header

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

Return to “Issues”