A simple HTTP request, it took me almost a day, just because a httpclient implementation is somewhat inconsistent with the specification.
The server uses the Digest authentication, uses the Nginx, we use the IOS,JS to write the program all to have the smooth access, the browser, the curl naturally also is easy, but the Java program Access always reported 401 or 400 error.
Grab packet analysis, your own program than the program generated by the response value, there is no problem, open Nginx log, only see the error, also did not indicate the cause of the error.
Later, after careful comparison between normal requests and requests from the Java program, it was found that the values in Qop and algorithm two fields in the Java request did not have double quotes.
Try upgrading httpclient to the latest version, or the same.
Try to use okhttp, found that does not support digest certification, installed a third-party extension okhttp-digest, which is also deducted from the httpclient, so there are the same problem.
Finally, there is no way, rewrite the related method, Qop and algorithm two fields in quotation marks, rerun, return HTTP 200.
This must be httpclient and nginx incompatible, both are industrial-grade mature tools, how can make such a low-level error? I have to make a referee for them.
Look at the standard specification RFC2617, found that there is no very clear requirements for this piece, but there are requirements auth-req these two values are quoted, Auth-resp not clear, but in theory, nginx more reasonable, so the board hit httpclient above.
Final implementation code (slightly)
Apache HttpClient about a big pit of digest