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);
}
});
精彩评论