晚上没事写了一点儿!可以登陆上校友路,但是似乎是记住了cookies,登陆再退出好几次,登陆次数还是不变。改天继续烟酒cookies!估计cookies有一个超时限制。- -!?怎么回事腻!
package fresh;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
/**
* @author WS
* @created at 2006-4-7 20:48:00
*/
* @author WS
* @created at 2006-4-7 20:48:00
*/
public class TestConnect {
private static String loginid = "";
private static String loginid = "";
private static String appid = "";
private static String ru = "";
private static String fl = "";
private static String ct = "";
private static String vr = "";
private static String sg = "";
private static String uid = "";
private static String passwd = "";
private static String utype = "";
private static String query_str = "";
//
http://passport.sohu.com/login.jsp
// http://localhost:80/login.jsp
private static final String login_url = " http://passport.sohu.com/login.jsp";
// http://localhost:80/login.jsp
private static final String login_url = " http://passport.sohu.com/login.jsp";
/**
* @param args
*/
public static void main(String[] args) {
try {
URL u = new URL(
" http://alumni.chinaren.com/class/class_index.jsp?classuuid=2817034544986595867");
URLConnection uc = u.openConnection();
uc.setReadTimeout(20000);
InputStream raw = uc.getInputStream();
InputStreamReader isr = new InputStreamReader(raw);
BufferedReader br = new BufferedReader(isr);
String s;
int i = 0;
while ((s = br.readLine()) != null) {
i++;
if (i == 410) {
System.out.println(s);
}
if (i >= 412 && i <= 417) {
System.out.println(s);
if (s.indexOf("appid") > 0) {
appid = getValue(s);
} else if (s.indexOf("ru") > 0) {
ru = getValue(s);
} else if (s.indexOf("fl") > 0) {
fl = getValue(s);
} else if (s.indexOf("ct") > 0) {
ct = getValue(s);
} else if (s.indexOf("vr") > 0) {
vr = getValue(s);
} else if (s.indexOf("sg") > 0) {
sg = getValue(s);
}
loginid = " ******@chinaren.com";
uid = "*****";
passwd = "*****";
utype = "0";
} else if (i > 418) {
break;
}
// Test
if (i == 412 && false) {
System.out.println("ThisLine:/n" + s);
System.out.println(s.indexOf("value") + "And"
+ s.indexOf("/">"));
System.out.println(s.substring(s.indexOf("value=/"") + 7, s
.indexOf("/">")));
}
}
br.close();
sendLogon();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
* @param args
*/
public static void main(String[] args) {
try {
URL u = new URL(
" http://alumni.chinaren.com/class/class_index.jsp?classuuid=2817034544986595867");
URLConnection uc = u.openConnection();
uc.setReadTimeout(20000);
InputStream raw = uc.getInputStream();
InputStreamReader isr = new InputStreamReader(raw);
BufferedReader br = new BufferedReader(isr);
String s;
int i = 0;
while ((s = br.readLine()) != null) {
i++;
if (i == 410) {
System.out.println(s);
}
if (i >= 412 && i <= 417) {
System.out.println(s);
if (s.indexOf("appid") > 0) {
appid = getValue(s);
} else if (s.indexOf("ru") > 0) {
ru = getValue(s);
} else if (s.indexOf("fl") > 0) {
fl = getValue(s);
} else if (s.indexOf("ct") > 0) {
ct = getValue(s);
} else if (s.indexOf("vr") > 0) {
vr = getValue(s);
} else if (s.indexOf("sg") > 0) {
sg = getValue(s);
}
loginid = " ******@chinaren.com";
uid = "*****";
passwd = "*****";
utype = "0";
} else if (i > 418) {
break;
}
// Test
if (i == 412 && false) {
System.out.println("ThisLine:/n" + s);
System.out.println(s.indexOf("value") + "And"
+ s.indexOf("/">"));
System.out.println(s.substring(s.indexOf("value=/"") + 7, s
.indexOf("/">")));
}
}
br.close();
sendLogon();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void add(Object name, Object value) {
if (!query_str.trim().equals(""))
query_str += "&";
query_str += URLEncoder.encode(name.toString()) + "="
+ URLEncoder.encode(value.toString());
}
if (!query_str.trim().equals(""))
query_str += "&";
query_str += URLEncoder.encode(name.toString()) + "="
+ URLEncoder.encode(value.toString());
}
private static void sendLogon() {
try {
URL u = new URL(login_url);
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(uc
.getOutputStream(), "ASCII");
add("appid", appid);
add("ru", ru);
add("fl", fl);
add("ct", ct);
add("vr", vr);
add("sg", sg);
add("uid", uid);
add("passwd", passwd);
add("utype", utype);
add("loginid", loginid);
add("uid", uid);
try {
URL u = new URL(login_url);
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(uc
.getOutputStream(), "ASCII");
add("appid", appid);
add("ru", ru);
add("fl", fl);
add("ct", ct);
add("vr", vr);
add("sg", sg);
add("uid", uid);
add("passwd", passwd);
add("utype", utype);
add("loginid", loginid);
add("uid", uid);
out.write(query_str);
System.out.println(query_str);
out.write("/r/n");
out.flush();
out.close();
InputStream in = uc.getInputStream();
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
String ss;
while ((ss = br.readLine()) != null) {
System.out.println(ss);
}
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(query_str);
out.write("/r/n");
out.flush();
out.close();
InputStream in = uc.getInputStream();
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
String ss;
while ((ss = br.readLine()) != null) {
System.out.println(ss);
}
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static String getValue(String src) {
String tmp = "";
try {
tmp = src
.substring(src.indexOf("value=/"") + 7, src.indexOf("/">"));
} catch (StringIndexOutOfBoundsException siobe) {
System.out.println("WrongLineNum!");
}
return tmp;
}
}
String tmp = "";
try {
tmp = src
.substring(src.indexOf("value=/"") + 7, src.indexOf("/">"));
} catch (StringIndexOutOfBoundsException siobe) {
System.out.println("WrongLineNum!");
}
return tmp;
}
}