0

我想在java中执行一个web服务。Web 服务实现了摘要认证。

Digest 需要以下变量:nonce、realm、qop、userName、password。

我尝试了以下代码,但它引发了 401 错误:

URL url = new URL(str);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setRequestMethod("POST");           
httpCon.setDoInput(true);
httpCon.setUseCaches(false);
httpCon.setAllowUserInteraction(false);
httpCon.setDoOutput(true);
httpCon.setRequestProperty("Content-Type", "application/json");
httpCon.setRequestProperty("Accept", "application/json; charset=utf-8");
httpCon.setRequestProperty("Authorization", "Digest username='utoter1@cust1',     realm='Invene', nonce='MTM4MjQ0NzgTGE1NWJkNg==', qop=auth");

OutputStream outstream = httpCon.getOutputStream();
OutputStreamWriter out = new OutputStreamWriter(outstream);
out.write(jsnStr);
int httpResponceCode = httpCon.getResponseCode();
String httpResponceMessage = httpCon.getResponseMessage();

请指导我解决问题。

4

0 回答 0