pashky / restclient.el

HTTP REST client tool for emacs
1.99k stars 164 forks source link

User-Agent header is required #202

Open alexei-28 opened 5 years ago

alexei-28 commented 5 years ago

I has url

https://api.pro.coinbase.com/products

If I open them in Chrome server success return json. Nice.

But if I try open it via restclient like this:

:PRODUCTION = https://api.pro.coinbase.com
:BASE = :PRODUCTION

# Get all products(symbols/pairs)
GET :BASE/products

I get error from server:

{
  "message": "User-Agent header is required."
}
// GET https://api.pro.coinbase.com/products
// HTTP/1.1 400 Bad Request
// Date: Wed, 16 Jan 2019 13:52:54 GMT
// Content-Type: application/json; charset=utf-8
// Content-Length: 44
// Connection: keep-alive
// ETag: W/"2c-xgaU8stueD20U2f68lAoreiwDOI"
// CF-Cache-Status: EXPIRED
// Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
// Server: cloudflare
// CF-RAY: 49a110aefeffb6e0-KIV
// Request duration: 0.566501s
dakra commented 5 years ago

I just tried your examle and it works for me.

But to your error, it even tells you what you got wrong. It expects a 'User-Agent' string. This has nothing to do with restclient, it's just that you have to provide all headers they require.

alexei-28 commented 5 years ago

After I set user agent like this:

:PRODUCTION = https://api.pro.coinbase.com
:BASE = :PRODUCTION

# Get all products(symbols/pairs)
GET :BASE/products
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0

Now success get response from server from by restclient file

ccarlile commented 7 months ago

Why doesn't restclient send a user agent? I have found several APIs that behave strangely when a user-agent string isn't provided, and often error messages returned aren't so precise in specifying what's wrong as the one posted in the OP.

Is it possible to modify restclient to provide a defcustom or something that would allow a default user-agent string to be set?