跨服务器登录验证(单点登录SSO)的过程和Java实现(2)
发布时间:2021-06-05
发布时间:2021-06-05
Scanner in = new Scanner(System.in);
String username = in.next();
System.out.print("输入密码:");
String password = in.next();
try {
// 本地认证
String cookie = postLogin(username, password);
if (cookie == null) {
return null;
}
// 服务器远程认证
String url = getLogin2(cookie);
if (url == null) {
return null;
}
// 远程访问认证
String cookie2 =
getLogin3(url.substring("".length())); // System.out.println(cookie2);
return cookie2;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
private static String postLogin(String username, String password) throws Exception {
Socket socket = new Socket("", 80);
try {
StringBuilder sb = new StringBuilder();
sb.append("POST /signin?f=out HTTP/1.1\r\n");
sb.append("Host: \r\n");
sb.append("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3\r\n");
sb.append("Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"); sb.append("Accept-Language: zh-cn,zh;q=0.5\r\n");
sb.append("Accept-Encoding: gzip,deflate\r\n");
sb.append("Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n"); sb.append("Referer: /3rdServices/50hero\r\n");
sb.append("Content-Type:
application/x-www-form-urlencoded\r\n");
String data =
上一篇:小学英语教材教法测试题(五)
下一篇:后勤保障工作措施