我想在java中执行Web服务。 Web服务已实现摘要式身份验证。
摘要需要以下变量: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();
请引导我解决问题。