Apache HttpClient about a big pit of digest

Source: Internet
Author: User
Tags http 200

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.