I have created a class using API end point URL, While getting its response we are able to observe blank spaces in the output string which should not be present.

Please help me out with a solution. Please find the attached screenshot for reference. enter image description here

  • You need to do url encode to remove this (line no 38) – Tushar Sharma Aug 3 '15 at 12:37

You have to Encode the URL with EncodingUtil.urlEncode as below. Hope this will help.

HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();

String endpoint = 'http://api-adresse.data.gouv.fr/search?q='+ EncodingUtil.urlEncode('41,Boulevard de strasbourg','UTF-8');

try {
    res = http.send(req);
} catch(System.CalloutException e) {
    System.debug('Callout error: '+ e);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.