package com.main;
import java.io.InputStreamReader;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class Login {
public static void main(String[] args) {
String loginUrl = "https://www.oschina.net/action/user/hash_login";
String email = "email";
String password = "password";
try {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
engine.eval(new InputStreamReader(Login.class
.getResourceAsStream("/sha1.js")));
Object t = engine.eval("CryptoJS.SHA1('" + password
+ "').toString();");
System.out.println(t);
HttpClient client = new HttpClient();
NameValuePair[] nameValuePairs = {
new NameValuePair("email", email),
new NameValuePair("pwd", t.toString()) };
PostMethod postMethod = new PostMethod(loginUrl);
postMethod.setRequestBody(nameValuePairs);
client.getParams().setCookiePolicy(
CookiePolicy.BROWSER_COMPATIBILITY);
client.executeMethod(postMethod);
Cookie[] cookies = client.getState().getCookies();
String tmpcookies = "";
for (Cookie c : cookies) {
tmpcookies += c.toString() + ";";
}
GetMethod getMethod = new GetMethod(
"http://my.oschina.net/snageyang/admin/inbox");
getMethod.setRequestHeader("cookie", tmpcookies);
client.executeMethod(getMethod);
String text = getMethod.getResponseBodyAsString();
System.out.println(text);
} catch (Exception e) {
e.printStackTrace();
}
}
}
最近下载更多
最近浏览更多
cpbeyond588 LV1
2025年1月6日
微信网友_6776677869096960 LV1
2024年1月1日
huangqiong LV2
2023年12月24日
qq573914838 LV5
2023年10月14日
1358849392 LV21
2023年10月12日
微信网友_6231292751777792 LV1
2022年12月20日
发生的2564
2022年12月8日
暂无贡献等级
13093855955 LV1
2022年11月18日
492537243
2022年10月17日
暂无贡献等级
诗洛紫
2022年10月16日
暂无贡献等级

