You need to sign in to do that
Don't have an account?
Dev TNOPPV5
How to encode ' ' ( Space ) to %20 ?
Hello,
I am calling one rest api in salesforce. Following is the deatil code:
HttpRequest req = new HttpRequest();
req.setEndpoint('https://example.com'+lo[0].Company__c);
req.setMethod('GET');
req.setHeader('ACCEPT','application/xml');
req.setHeader('Authorization', authorizationHeader);
Http http = new Http();
HTTPResponse res = http.send(req);
system.debug('res:'+res);
In above code lo[0].Comapny__c value is " Test Example " . In this name there is space between Test and Example. When My code execute for this example it is given me blank response body.
I am passing like "TestExample" it is working. Actually when space came at that time "%20" should pass in that url.
I know how to do in .net , PHP, JAva ( line encodeURI("Test Example)").
How can i do this in Salesforce? Please help me.
I am calling one rest api in salesforce. Following is the deatil code:
HttpRequest req = new HttpRequest();
req.setEndpoint('https://example.com'+lo[0].Company__c);
req.setMethod('GET');
req.setHeader('ACCEPT','application/xml');
req.setHeader('Authorization', authorizationHeader);
Http http = new Http();
HTTPResponse res = http.send(req);
system.debug('res:'+res);
In above code lo[0].Comapny__c value is " Test Example " . In this name there is space between Test and Example. When My code execute for this example it is given me blank response body.
I am passing like "TestExample" it is working. Actually when space came at that time "%20" should pass in that url.
I know how to do in .net , PHP, JAva ( line encodeURI("Test Example)").
How can i do this in Salesforce? Please help me.
If you are looking for URL encoding, there is this utility "EncodingUtil" class into the Apex API that you can make use of as: For more details - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_encodingUtil.htm (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_encodingUtil.htm" target="_blank)
I tried that but when is do like this:
result comes like "Test+Example"
Result I am expecting like: "Test%20Example"
Result should be like: Test%20Example
I did not resolve this using above solution.
However, if still your endpoint expect it to be %20 only, you need to handle it like special case, something like: Not recommended, though, you can make it done!
It is not working. I tried this yesterday. Thanks for help. Please let me know if you have any other solution.
Did anyone found the solution to this?
I need "%20" instead of "+" while encoding the string.
String query = 'Test Example';
Output should be: Test%20Example
Please help me out.
Thanks in advance.
Have you found solution for this?
I am using the below code for this.
Have you got the solution I have the same requirement
please replay how you solved this?
There is no need to use replace('+', '%20') .
You can only use :
String query = EncodingUtil.urlEncode('Test Example', 'UTF-8');
it will work as expected in URL no need to replace '+' with '%20'.