标签:
验证网上的获取网页post和cookice的JAVA代码,
List<Cookie> cookies; //保存获取的cookie HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse; [java] view plaincopy String uriAPI = "http://210.43.188.41/_data/index_LOGIN.aspx"; [java] view plaincopy /* 建立HTTP Post连线 */ HttpPost httpRequest = new HttpPost(uriAPI); List<NameValuePair> params = new ArrayList<NameValuePair>(); [java] view plaincopy params.add(new BasicNameValuePair("PassWord", "*****"); //这里的密码我用*取代了 params.add(new BasicNameValuePair("UserID", "201150080223"); //这是学号 params.add(new BasicNameValuePair("Sel_Type", "STU")); //以学生身份登录 [java] view plaincopy try { // 发出HTTP request httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); // 取得HTTP response httpResponse = client.execute(httpRequest); //执行 // 若状态码为200 ok if (httpResponse.getStatusLine().getStatusCode() == 200) { //返回值正常 // 获取返回的cookie cookies = ((AbstractHttpClient) client).getCookieStore().getCookies(); } else { } } catch (Exception e) { e.printStackTrace(); }
标签:
原文地址:http://www.cnblogs.com/helloalbert/p/4504701.html