private NameValuePair[] data = null;//实例化后传入HttpClient http = new HttpClient();
http.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
http.getHostConfiguration().setHost("www.91job.com", 80, "http");

PostMethod pm = new PostMethod("http://www.91job.com/login.aspx");data[0].setValue("***");
data[1].setValue("***");

pm.setRequestBody(data);

int resultState = http.executeMethod(pm);
我用正确的用户名和密码然后把信息在打印出来不对,网上说PostMethod不会转向别的地址,然后我在用GetMethod去转向一个需要登陆的地址,然后我看了下源码还是有没有登陆等信息跳出..然后resultState都为200

解决方案 »

  1.   

    200说明成功了,跳转不跳转要设定redirect呢。
    如下代码,lz试试,可以用firebug看看你的请求是POST还是GET,以及参数如何发送的。import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;public class Test1 {
        private static String getStaticPage(String surl) {
            String htmlContent = "";
            try {
                java.io.InputStream inputStream;
                java.net.URL url = new java.net.URL(surl);
                java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url
                        .openConnection();
                connection.connect();
                inputStream = connection.getInputStream();
                byte[] bytes = new byte[1024 * 2000];
                int index = 0;
                int count = inputStream.read(bytes, index, 1024 * 2000);
                while (count != -1) {
                    index += count;
                    count = inputStream.read(bytes, index, 1);
                }
                htmlContent = new String(bytes, "UTF-8");
                connection.disconnect();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return htmlContent.trim();
        }    public static void main(String[] args) {
            try {
                String src = getStaticPage("http://www.google.com");
                File file = new File("d:\\aa.html");
                FileWriter resultFile = new FileWriter(file);
                PrintWriter myFile = new PrintWriter(resultFile);// 写文件
                myFile.println(src);
                resultFile.close();
                myFile.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
      

  2.   

    直接访问 http://www.91job.com/person/guanli-index.aspx 这个链接 不就可以了
    在get的方法中加入cookie的值
     method.setRequestHeader("Cookie","cookie的值")
      

  3.   

    一般POST发送你参数又看不到的
      

  4.   

    用工具httpwatch 查看,你可以自己人工登陆追踪cookie。 firefox的httpfox也可以追踪的