使用Java发送HTTP POST请求并在登录页面后访问链接

时间:2019-02-15 10:47:09

标签: java apache apache-httpclient-4.x apache-httpcomponents

我是http帖子请求中的新手,我不知道登录后是否可以访问,如果我可以访问登录页面中的另一个URL,并且访问此URL之后,我需要访问我拥有的最后一个URL中的另一个URL访问。

登录表单->与URL链接->与URL链接;

我正在使用来自Apache的HttpComponents。

我在住所有以下密码。

    public static void main(String[] args) throws ClientProtocolException, IOException, InterruptedException {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpPost httppost = new HttpPost("http://192.168.15.1/cgi-bin/device-management-resets.cgi");

    // Request parameters and other properties.
    List<NameValuePair> params = new ArrayList<NameValuePair>(2);
    params.add(new BasicNameValuePair("Loginuser", "admin"));
    params.add(new BasicNameValuePair("LoginPassword", "u774iwvh"));

    //Execute and get the response.
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();

    if (entity != null) {
        try (InputStream instream = entity.getContent()) {
            System.out.println("GET IN");
            Thread.sleep(2000);
            //TRYING ACCESS ANOTHER LINK HERE!!!!!
        }
    }        

}

有人想帮我吗?

0 个答案:

没有答案