So I am encoded the string to search before I make the call. I am unable to get results for names with spaces. On Mashape I saw the string to encoded thrice. That also did not work. How should I pass the string? Specially the one with spaces?
Thanks for the help
Great and fast API so far!
Join in the discussion - add comment below:
I had the issue with spacing when using cURL in php.
Using rawurlencode( $myVariable ) encodes spaces as ‘%20’ which fixed my issue.
UPDATE. These work OK with the mashape API. Notice the <code>%2520</code> part
<pre><code>
HttpResponse<JsonNode> response = Unirest.get(“https://restcountries-v1.p.mashape.com/name/united%20states”)
.header(“X-Mashape-Key”, “78mZ1stwA2msh8ifjBMAo1ltPsjyp1HQk8JjsnUG6XNABnfdO8”)
.asJson();
</code></pre>
<pre><code>
HttpResponse<JsonNode> response = Unirest.get(“https://restcountries-v1.p.mashape.com/subregion/western%20asia”)
.header(“X-Mashape-Key”, “78mZ1stwA2msh8ifjBMAo1ltPsjyp1HQk8JjsnUG6XNABnfdO8”)
.asJson();
</code></pre>
I dont quite understand how the mashape API handles spaces in the request URL. If you use my API directly like:
HttpResponse<JsonNode> response = Unirest.get(“http://restcountries.eu/rest/v1/name/united states”).asJson();
Then it’s OK. Is it ok with you to do it like this?
Hi! I’m very sorry for taking so long to give you an answer. I will take a look today and hopefully get back to you before tomorrow.
Found something odd. For all api’s apart from subregion, first we need to encode input string and replace ‘+’ with ‘%20’ (at least on java side).
For subregion, first need to replace ’ ’ with ‘%20’ and then encode.
The above works for me.
Please anyone let me know if I am going wrong somewhere.
Thanks