如何使用摘要式身份验证在java中执行Web服务?

时间:2013-10-23 10:39:18

标签: java json web-services digest-authentication

我想在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();

请引导我解决问题。

0 个答案:

没有答案