Voltaire
Posts: 0
Joined: Thu Apr 09, 2015 8:48 pm

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

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

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

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

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?

Voltaire
Posts: 0
Joined: Thu Apr 09, 2015 8:48 pm

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

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.

Voltaire
Posts: 0
Joined: Thu Apr 09, 2015 8:48 pm

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

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.

Return to “Issues”