问题描述
- 模拟登录正方教务系统重定向页面拿到的状态码为什么 总是200不是302
-
- 请求代码
List pairs = new ArrayList();
pairs.add(new BasicNameValuePair("__VIEWSTATE", "dDwyODE2NTM0OTg7Oz5hS%2FqlazCCYK7Agp6rx5GFtdHxlg%3D%3D"));
pairs.add(new BasicNameValuePair("txtUserName", username));
pairs.add(new BasicNameValuePair("TextBox2", pass));
pairs.add(new BasicNameValuePair("RadioButtonList1","%D1%A7%C9%FA"));//选择你是以什么身份进入%D1%A7%C9%FA
pairs.add(new BasicNameValuePair("Button1", ""));
pairs.add(new BasicNameValuePair("lbLanguage", ""));
pairs.add(new BasicNameValuePair("hidPdrs", ""));
pairs.add(new BasicNameValuePair("hidsc", ""));String info = ""; try { //该网址对应教务系统输入学号密码登入的那个界面 info = HttpUtil.postUrl("http://" + myUrl + "/default2.aspx", pairs, mHttpClient, ""); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.i("tag", "info===="+info);
-
执行代码
public static String postUrl(String url, List pairs,
DefaultHttpClient httpClient, String setHeader)
throws ClientProtocolException, IOException {HttpPost request = new HttpPost(url); request.setHeader("Referer", setHeader); httpClient.getParams().setParameter( CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); // 设置请求超时时间 httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); // 读取超时 HttpResponse response = httpClient.execute(request); /* * 根本没走这个if */ if(response.getStatusLine().getStatusCode() == 302||response.getStatusLine().getStatusCode() == 301){ //获取响应的cookie值 String cookie = response.getFirstHeader("Set-Cookie").getValue(); //获取头部信息中Location的值 String location = response.getFirstHeader("Location").getValue(); return location; }else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(response.getEntity()); } else { return null; }
}
- 抓包图片
- 有做过模拟登陆教务系统的大神看到这个问题能不能留个联系方式请教一下
- 请求代码
解决方案
你是不是开了自动重定向
http://blog.csdn.net/memray/article/details/7998388
时间: 2024-10-20 15:36:35