利用URL在后台登录另一个系统 有一个老系统可以用URL这样登录http://www.test.com/login?username=admin&pwd=123我在现在开发的系统中要怎样登录这个系统呢?我不想用直接跳传的方式登录!请高人指点! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用ajax或者异步提交可以考虑一下 import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;public class Test1 { private static String getStaticPage(String surl) { String htmlContent = ""; try { java.io.InputStream inputStream; java.net.URL url = new java.net.URL(surl); java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url .openConnection(); connection.connect(); inputStream = connection.getInputStream(); byte[] bytes = new byte[1024 * 2000]; int index = 0; int count = inputStream.read(bytes, index, 1024 * 2000); while (count != -1) { index += count; count = inputStream.read(bytes, index, 1); } htmlContent = new String(bytes, "UTF-8"); connection.disconnect(); } catch (Exception ex) { ex.printStackTrace(); } return htmlContent.trim(); } public static void main(String[] args) { try { String src = getStaticPage("http://www.google.com"); File file = new File("d:\\aa.html"); FileWriter resultFile = new FileWriter(file); PrintWriter myFile = new PrintWriter(resultFile);// 写文件 myFile.println(src); resultFile.close(); myFile.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}HttpURLConnection,或者HttpClient httpclient后台处理可以考虑下 http://www.iteye.com/topic/638206 你原来的老系统是用什么开发的,如果有源码的话,可以在原来的老系统嫁接个webService做为一个接口,再在现在开发的系统做个客户端,想怎么调就怎么调,用Xfire、cxf就可以的 同意。或者http。你那个是啥系统,真慢 哈哈,朋友们我发的那个地址是一个假的,只是做为比喻的。我使用过httpClient,登录成功并已经可以获取header中的Set-Cookie,但是当我在地址栏输入老系统还是须要登录! 你在server端取得了cookie值,也得设置到前端才行啊。 response set cookies。当然,如果涉及到cross domain,set cookie 可能也有问题。你gg一下 单点登录, 解决方式非常多。按照你说的:有一个老系统可以用URL这样登录http://www.test.com/login?username=admin&pwd=123。如果 访问这个链接了,就可以访问老系统的其他保护页面,那么,最简单的方式:在你的新系统页面放这么一段:<iframe width=0 height=0 src="http://www.test.com/login?username=admin&pwd=123"/> <iframe width=0 height=0 src="http://www.test.com/login?username=admin&pwd=123"/>这个不错,我以前就用过,不过是在一个系统(A)中引用另外的一个系统(B)的页面,B系统设有过滤器,打开B系统的页面时总跳转到登录页面,所以我就采用这种方式先登录B系统。 奇怪的struts2字符串比较 继续表单按钮问题.. 我这里为什么老出错啊 java江西群 请教怎样判断两个数据集合是否有交集?? strut 昨天是好的 今天就坏了!!! 各位大虾,请教一个问题! 关于jfreereport,急,急,急在线等候 oracle下如何想数据库插入图片? sql server2000 jdbc 驱动中文乱码?已经在 JSP 程序加了“<%@ page contentType="text/html; charset=GBK" %>” JSP中出现乱码,求解! STRUTS2 Java异常 再次疑惑
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;public class Test1 {
private static String getStaticPage(String surl) {
String htmlContent = "";
try {
java.io.InputStream inputStream;
java.net.URL url = new java.net.URL(surl);
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url
.openConnection();
connection.connect();
inputStream = connection.getInputStream();
byte[] bytes = new byte[1024 * 2000];
int index = 0;
int count = inputStream.read(bytes, index, 1024 * 2000);
while (count != -1) {
index += count;
count = inputStream.read(bytes, index, 1);
}
htmlContent = new String(bytes, "UTF-8");
connection.disconnect();
} catch (Exception ex) {
ex.printStackTrace();
}
return htmlContent.trim();
} public static void main(String[] args) {
try {
String src = getStaticPage("http://www.google.com");
File file = new File("d:\\aa.html");
FileWriter resultFile = new FileWriter(file);
PrintWriter myFile = new PrintWriter(resultFile);// 写文件
myFile.println(src);
resultFile.close();
myFile.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
HttpURLConnection,或者HttpClient
可以考虑下
同意。或者http。你那个是啥系统,真慢
我使用过httpClient,登录成功并已经可以获取header中的Set-Cookie,但是当我在地址栏输入老系统还是须要登录!
当然,如果涉及到cross domain,set cookie 可能也有问题。你gg一下 单点登录, 解决方式非常多。按照你说的:有一个老系统可以用URL这样登录http://www.test.com/login?username=admin&pwd=123。如果 访问这个链接了,就可以访问老系统的其他保护页面,那么,最简单的方式:在你的新系统页面放这么一段:<iframe width=0 height=0 src="http://www.test.com/login?username=admin&pwd=123"/>
这个不错,我以前就用过,不过是在一个系统(A)中引用另外的一个系统(B)的页面,B系统设有过滤器,打开B系统的页面时总跳转到登录页面,所以我就采用这种方式先登录B系统。