本文整理匯總了Java中com.gargoylesoftware.htmlunit.Page.getWebResponse方法的典型用法代碼示例。如果您正苦於以下問題:Java Page.getWebResponse方法的具體用法?Java Page.getWebResponse怎麽用?Java Page.getWebResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.gargoylesoftware.htmlunit.Page
的用法示例。
在下文中一共展示了Page.getWebResponse方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDocumentWithoutGateway
import com.gargoylesoftware.htmlunit.Page; //導入方法依賴的package包/類
private static DownloadableDocument getDocumentWithoutGateway(Page directDownloadPage, String courseName, Term term) {
String downloadPageURL = directDownloadPage.getUrl().toString();
WebResponse response = directDownloadPage.getWebResponse();
String contentDispositionHeader = response.getResponseHeaderValue("Content-Disposition");
String filename = fetchFileNameFromContentDisposition(contentDispositionHeader);
String extension = fetchFileExtension(filename);
String name = filename.substring(0, filename.indexOf(extension));
long size = fetchFileSizeFromResponse(response);
//todo find better solution for the zip-name hack
if (ZIP_EXTENSION.equals(extension)) {
name = clearZIPName(name);
name += "-" + size;
}
return new DownloadableDocument(name, downloadPageURL, courseName, extension, size, term);
}
示例2: checkForServerError
import com.gargoylesoftware.htmlunit.Page; //導入方法依賴的package包/類
private static void checkForServerError(final Page page) throws IOException {
final com.gargoylesoftware.htmlunit.WebResponse response = page.getWebResponse();
final int code = response.getStatusCode();
final boolean error;
if (code >= 400) {
error = true;
} else {
error = false;
}
if (error) {
final String responseMessage = response.getStatusMessage();
final String text = getPageSource(page);
final File output = File.createTempFile("server-error", ".html", new File("screenshots"));
final FileWriter writer = new FileWriter(output);
writer.write(text);
writer.close();
Assert.fail("Error loading page: "
+ page.getUrl() + " code: " + code + " message: " + responseMessage + " Contents of error page written to: "
+ output.getAbsolutePath());
}
}
示例3: saveDocument
import com.gargoylesoftware.htmlunit.Page; //導入方法依賴的package包/類
private void saveDocument(DownloadableDocument document, Path target) throws IOException {
Page downloadPage = browser.getPage(document.getDownloadLink());
WebResponse response = downloadPage.getWebResponse();
document.setSize(response.getContentLength());
try (CountingInputStream in = new CountingInputStream(response.getContentAsStream())) {
copy(in, target, document);
}
}
示例4: readURL
import com.gargoylesoftware.htmlunit.Page; //導入方法依賴的package包/類
@Override
protected Set<Validatable> readURL(LineFormater formater, MyHttpClient<?, ?> httpcx) throws HttpException, IOException {
@SuppressWarnings("unchecked")
MyHttpClient<String, Page> httpcxCast = (MyHttpClient<String, Page> ) httpcx;
Page page = httpcxCast.doCall(this.getRequestMethod(formater.getMyUrl()));
WebResponse webResponse = page.getWebResponse();
return super.parseInputStream(webResponse.getContentAsStream(), formater, new ArrayList<>());
}