HTTP Request works in Postman but not in HTTPIE

579 Views Asked by At

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

1

There are 1 best solutions below

5
Keegan Murphy On

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}