繁体   English   中英

RESTful服务中的摘要式身份验证

[英]DIgest authentication in RESTful service

我知道java中有类似下面的内容

urlConnection.setRequestProperty(“ Authorization”,“ Basic” + encodeString);

发送用于基本身份验证的授权标头以休息服务。 摘要认证是否有任何等效属性。

请提出建议。

这是HttpURLConnection的示例:

final String username = "username";
final String password = "password";

// Compatible for authentication Basic Digest Ntlm (not working with Negotiate)
Authenticator.setDefault(new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        PasswordAuthentication pa = new PasswordAuthentication (username, password.toCharArray());
        return pa;
    }
});

BufferedReader in = null;
StringBuffer sb = new StringBuffer();

try {
    HttpURLConnection connection = (HttpURLConnection) new URL("http://127.0.0.1:8180/").openConnection();

    in = new BufferedReader(new InputStreamReader(connection
            .getInputStream()));

    String line;
    while ((line = in.readLine()) != null) {
        sb.append(line).append("\n");
    }
} catch (java.net.ProtocolException e) {
    sb.append("User Or Password is wrong!");
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
} finally {
    try {
        if (in != null) {
            in.close();
        }
    } catch (Exception e) {
        System.out.println("Exception");
    }
}

System.out.println("The Data is: " + sb.toString());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM