Android DefaultHTTPClient 在 javascript 驱动的网站上通过 Post 请求填充表单

发布于 2024-11-12 00:54:49 字数 699 浏览 2 评论 0原文

我的问题与此类似: HTTPclient POST 有问题的网站

我使用篡改数据来查找所有正在进行的请求通过客户端和服务器。

我最初执行了 get 请求来加载页面并获取动态生成的字段值。然后,我为相关表单的所有输入字段创建了命名值对列表并执行了 post req,但是它将我重定向到错误页面。

我尝试以 stackoverflow 上建议的所有可能方式设置 cookie 并处理 sslfactory:

但它对我不起作用。

我不知道问题出在哪里,我什至在日志中没有收到任何错误。 我在这个问题上花了几天时间。

My problem is similar to this:
HTTPclient POST with problematic web site

I used tamper data to find all the request going through the client and server.

I initially executed the get request to load the page and get the dynamically generated field values. Then I created the list of named value pairs for all the input fields of the concerned form and executed post req, however it redirects me to an error page.

I tried setting cookie and handling sslfactory in all possible ways suggested on stackoverflow:

but it's not working for me.

I don't know what's the problem, I don't even get any error in logs.
I spent a couple of days on this single issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

再浓的妆也掩不了殇 2024-11-19 00:54:49

解决方案是使用相同的 HttpClient,无需维护 cookie 或其他任何内容。
首先找到所有使用篡改数据发出的请求(get 或 post)。然后提取动态生成的隐藏字段值:

public static String getPage(String sURL) throws HttpException {
    HttpGet method = new HttpGet(sURL);

    // method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
    // new DefaultHttpMethodRetryHandler(3, false));

    try {
        /*
        * int statusCode = client.execute(method); if (statusCode !=
        * HttpStatus.SC_OK) { System.err.println("Method failed: " +
        * method.getStatusLine()); }
        */HttpResponse res;
        res = client.execute(method);

        BasicResponseHandler myHandler = new BasicResponseHandler();
        String content = myHandler.handleResponse(res);
        //extract dynamic parameters here
        return content;
    } catch(...) {

    }
}

然后在后期使用此方法:

public static String postPage1(list of parameters to be passed in the post form) throws HttpException {
    BasicNameValuePair[] data = {
        new BasicNameValuePair("field name", "param1"),
        ......
    };
    HttpPost post = new HttpPost(sURL);

    // post.setRequestBody(data);
    try {
        post.setEntity(new UrlEncodedFormEntity(Arrays.asList(data)));

        HttpResponse res;
        res = client.execute(post);
        int statusCode;

        BasicResponseHandler myHandler = new BasicResponseHandler();
        String content = myHandler.handleResponse(res);
        return content;
    } catch (...) {

    }
}

就是这样。

The solution was using the same HttpClient without any need of maintaining cookies or anything else.
Firstly find all the request(get or post) those are made using tamper data. Then extract the dynamically generated hidden field values:

public static String getPage(String sURL) throws HttpException {
    HttpGet method = new HttpGet(sURL);

    // method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
    // new DefaultHttpMethodRetryHandler(3, false));

    try {
        /*
        * int statusCode = client.execute(method); if (statusCode !=
        * HttpStatus.SC_OK) { System.err.println("Method failed: " +
        * method.getStatusLine()); }
        */HttpResponse res;
        res = client.execute(method);

        BasicResponseHandler myHandler = new BasicResponseHandler();
        String content = myHandler.handleResponse(res);
        //extract dynamic parameters here
        return content;
    } catch(...) {

    }
}

Then for post use this method:

public static String postPage1(list of parameters to be passed in the post form) throws HttpException {
    BasicNameValuePair[] data = {
        new BasicNameValuePair("field name", "param1"),
        ......
    };
    HttpPost post = new HttpPost(sURL);

    // post.setRequestBody(data);
    try {
        post.setEntity(new UrlEncodedFormEntity(Arrays.asList(data)));

        HttpResponse res;
        res = client.execute(post);
        int statusCode;

        BasicResponseHandler myHandler = new BasicResponseHandler();
        String content = myHandler.handleResponse(res);
        return content;
    } catch (...) {

    }
}

That's it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文