0

我将如何继续使用通过使用 Apache 的 httpcomponents 获得的登录会话在需要您登录的站点上使用 html(代码方式)?

这是我使用 httpcomponents 时的样子:

        HttpPost httpost = new HttpPost("http://whatever.com/login.php");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("email", "whatever")); //set your own username
    nvps.add(new BasicNameValuePair("password", "whatever")); //set your own password

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

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

我认为我的问题的答案在于 HttpEntity 类的某个地方,但我觉得我被困住了..

澄清一下:如上所示登录后,我需要使用上面的会话访问一个页面,该页面需要您登录(例如 membersonly.php 或其他),然后阅读和使用内容从 Java 中的这个页面开始。

希望我让自己足够清楚:) 期待任何答案。

麦克风

4

1 回答 1

0

通常,HTTP 会话是通过从服务器接收到的cookie来跟踪的,这些 cookie必须在后续请求中发送。

只需按照执行基于表单的登录的示例即可。

于 2012-04-04T15:52:32.623 回答