From: Ahmed A. <asa...@ya...> - 2016-06-22 09:06:24
|
Hi Jack, Great. Still, if HtmlUnit behavior is different than real browsers, you could send the case to be fixed. Thanks,Ahmed From: jack <lil...@16...> To: htm...@li... Sent: Wednesday, June 22, 2016 9:47 AM Subject: Re: [Htmlunit-user] How to solve the cross domain problem caused by the error Hi asashour This is not a cross domain problem,the warning: Content is not allowed in prolog is the key I solved the problem by the following code new WebConnectionWrapper(wc) { public WebResponse getResponse(WebRequest request) throws IOException { WebResponse response = super.getResponse(request); if(request.getUrl().toExternalForm().contains("goalBf3.xml")){ System.out.println(response.getContentAsString("UTF-8")); String content = response.getContentAsString("UTF-8"); if(null != content && !"".equals(content)){ if(content.indexOf("<") != -1 && content.lastIndexOf(">") != -1 && content.lastIndexOf(">") > content.indexOf("<")) content = content.substring(content.indexOf("<"), content.lastIndexOf(">") + 1); } WebResponseData data = new WebResponseData(content.getBytes("UTF-8"), response.getStatusCode(), response.getStatusMessage(), response.getResponseHeaders()); response = new WebResponse(data, request, response.getLoadTime()); } return response; } } |