I need to test my http server responses in various cases, even for failed authentication. In case of failed authentication, my server returns 401 Unauthorized and also a response body which simple contains Unauthorized (or maybe some other detailed message).
Using e.g. curl or httpie, I got those response body in case of 401 response.
$ curl http://10.5.1.1/bla
Unauthorized
$ curl http://10.5.1.1/bla --digest --user joe:wrong
Unauthorized
$ http http://10.5.1.1/bla -b
Unauthorized
$ http http://10.5.1.1/bla -b --auth-type digest --auth joe:wrong
Unauthorized
But when trying this using wget, I got no output:
$ wget http://10.5.1.1/bla -q -O /dev/stdout
$ wget http://10.5.1.1/bla -q -O /dev/stdout --user joe --password wrong
wget returns with exitcode 6 in this case, but I need to check the response message.
Here is a dump of the complete traffic, captured using httpie:
$ http http://10.5.1.1/bla --print hbHB
GET /bla HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: 10.5.1.1
User-Agent: HTTPie/0.9.2
HTTP/1.1 401 Unauthorized
Connection: keep-alive
Content-Length: 13
Content-Type: text/plain
Date: 2017-08-27 23:01:07
Server: Vistra-I St10 SW218 HW010
WWW-Authenticate: Digest realm="Vistra-I", qop="auth", nonce="a0c5d461f2b74b2b797b62f54200d125", opaque="0123456789abcdef0123456789abcdef"
Unauthorized
(Note that the Unauthorized message in the response body ends with a new line character, that's why Content-Length: 13)
Same thing, if the server respond with 403 or 404 et cetera.
Any idea how to get the response body using wget in this case?
Edit 2017-09-22
Found --content-on-error option in my wget 1.17.1 (see also wget manual).
This works in case of e.g. response code 404 but not for 401 nor 5xx codes.
For 401 see this bug.