开发者

In htmlunit, how can I get the request, that would be sent on clicking an element?

I want to find a way to get the settings of the request that would be sent if I clicked a certain link. I want to send the request after making some开发者_高级运维 modifications. Is that possible?

Answering the comments, right now I want to change the headers sent, but post values or target url may be of interest too. I want to grab the request before it is sent, modify it and send.


You can subclass HttpWebConnection and manipulate the 'settings', as in:

    webClient.setWebConnection(new HttpWebConnection(webClient) {
        public WebResponse getResponse(WebRequestSettings settings) throws IOException {
            System.out.println(settings.getUrl());
            return super.getResponse(settings);
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜