本文整理了Java中org.apache.http.client.fluent.Request.userAgent
方法的一些代码示例,展示了Request.userAgent
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.userAgent
方法的具体详情如下:
包路径:org.apache.http.client.fluent.Request
类名称:Request
方法名:userAgent
暂无
代码示例来源:origin: org.apache.taverna.osgi/taverna-download-impl
private void downloadToFile(URI source, Path destination) throws DownloadException {
try {
// We want to handle http/https with HTTPClient
if (source.getScheme().equalsIgnoreCase("http") || source.getScheme().equalsIgnoreCase("https")) {
Request.Get(source).userAgent(getUserAgent()).connectTimeout(TIMEOUT).socketTimeout(TIMEOUT).execute()
.saveContent(destination.toFile());
} else {
// Try as a supported Path, e.g. file: or relative path
try {
Path path = Paths.get(source);
Files.copy(path, destination, StandardCopyOption.REPLACE_EXISTING);
} catch (FileSystemNotFoundException e) {
throw new DownloadException("Unsupported URL scheme: " + source.getScheme());
}
}
} catch (IOException e) {
throw new DownloadException(String.format("Error downloading %1$s to %2$s.", source, destination), e);
}
}
代码示例来源:origin: org.apache.taverna.osgi/taverna-download-impl
private String downloadHash(URI source) throws DownloadException {
try {
// We want to handle http/https with HTTPClient
if (source.getScheme().equalsIgnoreCase("http") || source.getScheme().equalsIgnoreCase("https")) {
logger.info("Downloading checksum " + source);
return Request.Get(source).userAgent(getUserAgent()).connectTimeout(TIMEOUT).socketTimeout(TIMEOUT).execute()
.returnContent().asString(StandardCharsets.ISO_8859_1);
} else {
// Try as a supported Path, e.g. file: or relative path
try {
Path path = Paths.get(source);
return Files.readAllLines(path, StandardCharsets.ISO_8859_1).get(0);
} catch (FileSystemNotFoundException e) {
throw new DownloadException("Unsupported URL scheme: " + source.getScheme());
}
}
} catch (IOException e) {
throw new DownloadException(String.format("Error downloading %1$s", source), e);
}
}
代码示例来源:origin: edu.jhuapl.dorset/dorset-core
private void prepareRequest(Request apacheRequest) {
if (getUserAgent() != null) {
apacheRequest.userAgent(getUserAgent());
}
if (getConnectTimeout() != null) {
apacheRequest.connectTimeout(getConnectTimeout());
}
if (getReadTimeout() != null) {
apacheRequest.socketTimeout(getReadTimeout());
}
if (!requestHeaders.isEmpty()) {
for (Map.Entry<String, String> entry : requestHeaders.entrySet()) {
apacheRequest.addHeader(entry.getKey(), entry.getValue());
}
}
}
代码示例来源:origin: reenWYJ/aude-distributed-spider-framework
/**
* 下载网页
*
* @param url
* @return
* @throws ClientProtocolException
* @throws IOException
*/
public String downloader(String url) throws ClientProtocolException, IOException {
String res = "";
Request request = Request.Get(url).connectTimeout(this.timeout);
if (this.agent != null) {
request = request.userAgent(this.agent);
}
if (this.cookie != null) {
request = request.addHeader("Cookie", this.cookie);
}
if (this.proxy != null) {
request = request.viaProxy(this.proxy);
}
res = request.execute().returnContent().asString();
return res;
}
}
内容来源于网络,如有侵权,请联系作者删除!