本文整理汇总了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<>());
}