function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daniel EbelDaniel Ebel 

Callout response exception: Illegal character sequence '\/' in string literal.

Hello everyone, 

this is my first question here, so please let me know if there's anything I can do to help you solve my problem quicker.

Setup: 
I'm sending a callout request in order to receive a response in JSON which contains a link to a website. The request looks like this:
 
http://api.ekomi.de/v3/putOrder?auth=accountId|password&order_id=E10002&version=cust-1.0.0&type=json
The response I'm getting is System.HttpResponse[Status=OK, StatusCode=200]

When I enter the callout request in my browser I get the following response:
{"link":"https:\/\/www.ekomi.de\/kundenmeinung.php?kunde=customerId&shop=accountId","hash":"2f68e87f2ba63a7929798400c372126b","known_since":"2017-07-24","done":1,"done_at":1500900539}

Problem
When I try to debug the response's body, I get the following error: System.CalloutException: Could not parse HTTP response body to string

When I take the string I got from the browser and try to debug it, I get the following error:
ERROR deploying ApexClass classes/SendEkomiReviewRequest.cls: Invalid string literal '{"link":"https:\/\/www.ekomi.de\/kundenmeinung.php?kunde=customerId&shop=accountId","hash":"2f68e87f2ba63a7929798400c372126b","known_since":"2017-07-24","done":1,"done_at":1500897547}'. Illegal character sequence '\/' in string literal.

Is there a way of altering the response I'm getting before it's parsed, so I can eventually deserialize it? 

Thanks for your help!
Daniel
Best Answer chosen by Daniel Ebel
Daniel EbelDaniel Ebel
I was given a solution to this problem. I'm not quite sure how or why it works, but it's good enough for me:

As mentioned, when I try to parse the response's body in a string or try to deserialize it with getBody(), I get the error message mentioned above.

The solution is to not get the response as a string but instead as a blob and then convert it to a string:
String responseBody = response.getBodyAsBlob().toString();

This way, I don't get the error message and i can deserialize the responseBody string.
​ 

All Answers

bk sbk s
Can you try asking the response team to encode the url in that case you can decode and deserialize.
Daniel EbelDaniel Ebel
I was given a solution to this problem. I'm not quite sure how or why it works, but it's good enough for me:

As mentioned, when I try to parse the response's body in a string or try to deserialize it with getBody(), I get the error message mentioned above.

The solution is to not get the response as a string but instead as a blob and then convert it to a string:
String responseBody = response.getBodyAsBlob().toString();

This way, I don't get the error message and i can deserialize the responseBody string.
​ 
This was selected as the best answer