/** * {@inheritDoc} */ @Override public Charset getCharset() { if (originalCharset_ == null) { originalCharset_ = getWebResponse().getContentCharset(); } return originalCharset_; }
/** * {@inheritDoc} */ @Override public String getContentType() { return getWebResponse().getContentType(); }
public String getRawPageText(WebClient client, String url) throws FailingHttpStatusCodeException, MalformedURLException, IOException { HtmlPage page = client.getPage(url); return page.getWebResponse().getContentAsString(); }
/** * {@inheritDoc} */ @Override public Charset getCharset() { if (originalCharset_ == null) { originalCharset_ = getWebResponse().getContentCharset(); } return originalCharset_; }
/** * {@inheritDoc} */ @Override public String getContentType() { return getWebResponse().getContentType(); }
/** * {@inheritDoc} * Not yet implemented. */ public String getDocumentURI() { return getWebResponse().getRequestSettings().getUrl().toExternalForm(); }
/** * {@inheritDoc} * Not yet implemented. */ public String getDocumentURI() { return getWebResponse().getRequestSettings().getUrl().toExternalForm(); }
private void checkRecursion() { final StackTraceElement[] elements = new Exception().getStackTrace(); if (elements.length > 500) { for (int i = 0; i < 500; i++) { if (!elements[i].getClassName().startsWith("com.gargoylesoftware.htmlunit.")) { return; } } final WebResponse webResponse = getWebResponse(); throw new FailingHttpStatusCodeException("Too much redirect for " + webResponse.getWebRequest().getUrl(), webResponse); } }
/** * Returns an auto-refresh string if specified. This will look in both the meta * tags and inside the HTTP response headers. * @return the auto-refresh string */ private String getRefreshStringOrNull() { final List<HtmlMeta> metaTags = getMetaTags("refresh"); if (!metaTags.isEmpty()) { return metaTags.get(0).getContentAttribute().trim(); } return getWebResponse().getResponseHeaderValue("Refresh"); }
WebClient client = new WebClient(); HtmlPage page = client.getPage("http://www.example.com/"); WebResponse response = page.getWebResponse(); for (NameValuePair header : response.getResponseHeaders()) { System.out.println(header.getName() + " : " + header.getValue()); }
@Test public void badRequest() throws IOException { webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.getOptions().setPrintContentOnFailingStatusCode(false); final HtmlPage page = webClient.getPage("http://localhost:8080/test/images/"); final WebResponse response = page.getWebResponse(); assertEquals(400, response.getStatusCode()); assertEquals("An image name is required.", response.getStatusMessage()); webClient.getOptions().setThrowExceptionOnFailingStatusCode(true); webClient.getOptions().setPrintContentOnFailingStatusCode(true); webClient.closeAllWindows(); }
WebClient webClient = new WebClient(); WebClient.setThrowExceptionOnScriptError(false); HtmlPage currentPage = webClient.getPage("http://myapp.com"); WebResponse response = currentPage.getWebResponse(); System.out.println(response.getResponseHeaders()); // And even in subsequent requests currentPage = webClient.getPage("http://myapp.com"); response = currentPage.getWebResponse(); System.out.println(response.getResponseHeaders());
public void print(HtmlPage page) { System.out.println("\n\n\n RAW REQUEST BODY \n" + getRawRequestBody()); System.out.println("\n\n\n RAW RESPONSE \n" + getRawResponse()); System.out.println("Response Headers: " + page.getWebResponse().getResponseHeaders()); System.out.println("\n\n\n ********************************* \n" + page.asXml()); System.out.println("\n\n\n **************************** \n" + webClient.getCookieManager().getCookies()); System.out.println("\n\n\n *********************************"); }
/** * Returns the value of the "URL" property. * @return the value of the "URL" property */ public String jsxGet_URL() { return getHtmlPage().getWebResponse().getRequestSettings().getUrl().toExternalForm(); }
/** * Refreshes the page by sending the same parameters as previously sent to get this page. * @return the newly loaded page. * @throws IOException if an IO problem occurs */ public Page refresh() throws IOException { return getWebClient().getPage(getWebResponse().getWebRequest()); }
/** * Refreshes the page by sending the same parameters as previously sent to get this page. * @return the newly loaded page. * @throws IOException if an IO problem occurs */ public Page refresh() throws IOException { return getWebClient().getPage(getWebResponse().getRequestSettings()); }
/** * Refreshes the page by sending the same parameters as previously sent to get this page. * @return the newly loaded page. * @throws IOException if an IO problem occurs */ public Page refresh() throws IOException { return getWebClient().getPage(getWebResponse().getRequestSettings()); }
/** * Refreshes the page by sending the same parameters as previously sent to get this page. * @return the newly loaded page. * @throws IOException if an IO problem occurs */ public Page refresh() throws IOException { return getWebClient().getPage(getWebResponse().getWebRequest()); }
/** * Refreshes the page by sending the same parameters as previously sent to get this page. * @return the newly loaded page. * @throws IOException if an IO problem occurs */ public Page refresh() throws IOException { return getWebClient().getPage(getWebResponse().getRequestSettings()); }
WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_9); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setRedirectEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setCssEnabled(true); HtmlPage page = (HtmlPage) webClient.getPage("http://www.sears.com/search=little tikes&Little Tikes?filter=Brand&keywordSearch=false&vName=Toys+%26+Games&catalogId=12605&catPrediction=false&previousSort=ORIGINAL_SORT_ORDER&viewItems=50&storeId=10153&adCell=W3"); WebResponse response = page.getWebResponse(); String content = response.getContentAsString(); System.out.println(page.getUrl());