REST Countries v1

GRATIS
Da apilayer | Aggiornamento hace un mes | Data
Popolarità

0.4 / 10

Latenza

34ms

Livello di servizio

100%

Health Check

N/A

Torna a tutte le discussioni

Unable to get results for names with spaces in them

Rapid account: Abhi 2 Rai
abhi2rai
hace 10 años

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 hace 4 años

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 hace 10 años

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 hace 10 años

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 hace 10 años

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 hace 10 años

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

Partecipa alla discussione - aggiungi un commento di seguito:

Accedi/Iscriviti per pubblicare nuovi commenti