1

I'm trying to make a simple http request to https://ip2country.info/ using httpie.

For the life of me I can't get it to work. I'm trying to request to this URL: https://api.ip2country.info/ip?5.6.7.8

When I use this in Postman it works perfectly. But in httpie here's my request and response:

Request: http api.ip2country.info ip==5.6.7.8 Response: HTTP/1.1 301 Moved Permanently

Any help would be appreciated!

Edit: Screenshots

httpie: enter image description here

postman: enter image description here

bugsyb
  • 5,662
  • 7
  • 31
  • 47
  • Can you take screenshots of both postman and httpie? I believe I know the issue but I want to verify the url and headers. – Keegan Murphy Dec 18 '21 at 16:49
  • @KeeganM Yep, just added screenshots – bugsyb Dec 18 '21 at 16:52
  • This has do with the URL schema, it's not sending the requests as HTTPS for some reason and keeps sending a redirect to the exact same url, but with https, which is a trait of nginx when listening on port 80. Im attempting to find a solution right now – Keegan Murphy Dec 18 '21 at 17:00

1 Answers1

1

Test Case

The request, as stands, to https://api.ip2country.info/ip?5.6.7.8 by httpie return a redirect error code, yet works in postman api.ip2country.info/ip?5.6.7.8.

Solution

The request works in postman because postman directly accesses the url with hard-coded query params. Httpie is supposed to be "easier" by allowing a builder interfact on the command line.

The command http api.ip2country.info ip==5.6.7.8 will essentially build a request to http://api.ip2country.info?ip=5.6.7.8 which is different then the intended url plugged into postman.

  • Intended: https://api.ip2country.info/ip?5.6.7.8
  • Actual: http://api.ip2country.info?ip=5.6.7.8

By directly coding the query params into httpie and changing the scheme to https like https api.ip2country.info/ip?5.6.7.1, a response of

{
    "countryCode": "DE",
    "countryCode3": "DEU",
    "countryEmoji": ""  ,
    "countryName": "Germany"
}

is retrieved. The only provided query param is a single key IP with no value, which httpie doesn't support in their builder (since it's fairly taboo), and requires it to just be manually appended to the end of the request URL with ?{ip}

Keegan Murphy
  • 767
  • 3
  • 14
  • Ah i see — that makes sense. However, the request still doesn't work in httpie. Here's what I tried: `http api.ip2country.info/ip?5.6.7.8` and my response was this: `no matches found: api.ip2country.info/ip?5.6.7.8` – bugsyb Dec 18 '21 at 18:21
  • Try using the keyword `https` instead of http. 90% of modern websites require https protocol – Keegan Murphy Dec 18 '21 at 18:30
  • Hmm, I tried this: `https api.ip2country.info/ip?5.6.7.8` and I get the same error: `api.ip2country.info/ip?5.6.7.8` – bugsyb Dec 18 '21 at 18:36
  • What installation method are you using for httpie? – Keegan Murphy Dec 18 '21 at 18:37
  • Im using pip and just tried the online one https://httpie.io/cli/run and got the intended response – Keegan Murphy Dec 18 '21 at 18:39