0

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

1
  • You need to do url encode to remove this (line no 38) Commented Aug 3, 2015 at 12:37

1 Answer 1

1

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');
req.setEndpoint(endpoint);
req.setMethod('GET');

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .