Page 1 of 1

Invalid character in the header of the server code response. XHR2 XHRResponse

Posted: Sat Dec 17, 2016 7:07 pm
by Voltaire

Hello, am using the server code , callRestApiGet
I am using the following script

var url = "http:/xxxxxxx/api/events"; // REST API URL
var XHRResponse = XHR2.send("GET", url, {});
Apperyio.response.success(XHRResponse.body, "application/json");

The problem am getting is with the json reply format, am getting the character ¿ in the top of the first array

¿{"events":[{"id":"169","title":".......

How can escape this character since I can not import the json reply as response due to an invalid character.

Thanks in advance


Invalid character in the header of the server code response. XHR2 XHRResponse

Posted: Sat Dec 17, 2016 7:24 pm
by Serhii Kulibaba

Hello Voltaire,

Could you run the same REST service with any 3rd-part REST client, e.g. with a POSTMAN? Do you get there the same response?


Invalid character in the header of the server code response. XHR2 XHRResponse

Posted: Sat Dec 17, 2016 9:03 pm
by Voltaire

Hello Segiy;

I found the error, it was the saving of the php file , I did modify it with notepad++ without encoding.

Now it is working fine. thanks for your quick reply, I have another question, If I want to send parameters from the the rest api service to the server code request, is it enough to include it in the service request, or I have to add parameters on the server code level and if yes, do I have to use the same name of parameters and how to get the value ?

If I was not clear enough, please advise to insert some examples to clarify my question.

Appreciated.


Invalid character in the header of the server code response. XHR2 XHRResponse

Posted: Sat Dec 17, 2016 9:32 pm
by Voltaire

I figured it out again :)
Code
code
var username = request.get("username");
var password = request.get("password");

var url = "http://xxxxxxxx/api/login&quot // REST API URL

var XHRResponse = XHR2.send("GET", url, {
"parameters": {
"username": username,
"password": password

}
});

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

Thanks anyway.