REST Countries v1

FREE
By apilayer | Updated vor 24 Tagen | Data
Popularity

0.4 / 10

Latency

37ms

Service Level

100%

Health Check

N/A

Back to All Discussions

Unable to get results for names with spaces in them

Rapid account: Abhi 2 Rai
abhi2rai
10 years ago

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!

Rapid account: Dtk
dtk Commented 4 years ago

I had the issue with spacing when using cURL in php.
Using rawurlencode( $myVariable ) encodes spaces as ‘%20’ which fixed my issue.

Rapid account: Fayder
fayder Commented 10 years ago

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>

Rapid account: Fayder
fayder Commented 10 years ago

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?

Rapid account: Fayder
fayder Commented 10 years ago

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.

Rapid account: Abhi 2 Rai
abhi2rai Commented 10 years ago

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

Join in the discussion - add comment below:

Login / Signup to post new comments