现在我需要用程序模拟登陆一下智联招聘。用我的方法行不通,应该是哪个地方少了点什么。主要代码如下:
HttpClient client = new HttpClient();
String loginUrl = url;
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,
"gbk");
PostMethod pMethod = new PostMethod(loginUrl);
NameValuePair[] postData = {
new NameValuePair("loginname", username),
new NameValuePair("password", password),
new NameValuePair("isautologin","1"),
new NameValuePair("int_count", "999"),
new NameValuePair("bkurl","")};
pMethod.setRequestBody(postData);
try {
client.executeMethod(pMethod);
GetMethod gm=doGetMethod("http://my.zhaopin.com/MYZHAOPIN/resume_index.asp?t=36284.3");
client.executeMethod(gm);
System.out.println(gm.getResponseBodyAsString());
Cookie[] cookies = client.getState().getCookies();// 获得登录的cookie
if (CommonResume.getCookies() != null) {
CommonResume.setCookies(null);
CommonResume.setCookies(cookies);// 保存cookie
} else {
CommonResume.setCookies(cookies);
}
} catch (Exception e) {
e.printStackTrace();
}
pMethod.releaseConnection();智联招聘发现是asp做的,我这个方法登录php做的网站和asp.net做的网站都可以。
谁能登录智联成功,马上结贴给分。

解决方案 »

  1.   

    这个和ASP,PHP什么的没有关系,
    我估计是有跳转你没有出来,你要看client.executeMethod(pMethod);的返回值。
    是不是302什么的。
    此外就是RequestHeader什么的,是不是都弄全了,建议你用firebug看看整个网络的流程,再来完成你的代码,我觉得快了~~~~
      

  2.   

    模拟请求ajax控制的页面大家有思路吗?智联招聘的登录有兴趣的不妨做做。
      

  3.   

    呵呵,,值得学习。我想请教一个问题,在前面的简单案例中,一般网站都能登录进去,但是类似如 中华英才网的登录 好像麻烦些,我弄了好长时间没有弄出来没有时间了BOSS 在催,能否帮我切磋下, 企业级:账号 zyrj_xu  密码xucong123456