java在发送cookie信息时读取网站信息

时间:2012-02-09 08:39:51

标签: java cookies

所以,基本上,我有一个小页面,我设置了密码,它使用一个简单的PHP表格来进行检查,

我希望通过发送cookie信息来获取表单所保护的信息,

在我的java文件中,它已经向表单发送请求以获取我的cookie信息,现在我希望将该cookie信息发回并阅读其下的纯文本,

我该怎么做?

这是我用来获取cookie的代码

        HttpPost httpost = new HttpPost("localhost/form.php");
        List <NameValuePair> nvps = new ArrayList <NameValuePair>();
        nvps.add(new BasicNameValuePair("user", "derp"));
        nvps.add(new BasicNameValuePair("pass", "derp1"));

        httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

        HttpResponse response = httpclient.execute(httpost);
        HttpEntity entity = response.getEntity();
        EntityUtils.consume(entity);

        List<Cookie> cookies = httpclient.getCookieStore().getCookies();
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("- " + cookies.get(i).toString());
            }

我怎么想再次请求页面,但是发回cookie所以它不显示表单,而是表单隐藏的文本

使用

排序
     URL url = new URL("http://localhost/~/test.php");
     HttpURLConnection conn = (HttpURLConnection) url.openConnection();

     conn.setRequestProperty("Cookie", cookies);

     BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
     String String;
     while ((String = in.readLine()) != null) {
         System.out.println(String);
     }
     in.close();

0 个答案:

没有答案