跨服务器登录验证(单点登录SSO)的过程和Java实现(4)

发布时间:2021-06-05

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("Cookie: " + cookie + "\r\n");

sb.append("\r\n");

OutputStream os = socket.getOutputStream();

os.write(sb.toString().getBytes("UTF-8"));

os.flush();

InputStream is = socket.getInputStream();

BufferedReader reader = new BufferedReader(new

InputStreamReader(is, "UTF-8")); // 读取结果

String line;

while ((line = reader.readLine()) != null) {

if (line.startsWith("location:")) {

return line.substring(10);

}

}

is.close();

reader.close();

return null;

} finally {

socket.close();

}

}

private static String getLogin3(String url) throws Exception { Socket socket = new Socket("", 80);

try {

StringBuilder sb = new StringBuilder();

sb.append("GET " + url + " 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");

精彩图片

热门精选

大家正在看