我尝试使用build.gradle文件在我的应用程序中包含httpmime,所有内容编译都很好.相反,当应用程序尝试实际使用MultipartEntityBuilder类时,日志上有一堆WARN级别消息说有问题.
以下是我的build.gradle对依赖项的摘录:
compile('org.apache.httpcomponents:httpmime:4.+') {
exclude module: "httpclient"
}
以下是错误:
10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm? VFY: unable to resolve static field 6967 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType; 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm? VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm? VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm? VFY: unable to resolve static field 6967 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType; 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm? VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm? …
java android apache-httpcomponents build.gradle android-gradle-plugin
有人可以向我解释一下参考HttpComponents PoolingHttpClientConnectionManager的内容setMaxPerRoute(max)和 setMaxTotal(max)做法吗?
面对这个奇怪的问题,从早上开始,我正在对一个特定的端点进行REST调用,该端点在页面中给出响应,所以我需要一次又一次地调用,直到所有页面都完成.我的代码工作正常,花花公子直到最后一页之后的最后一页我下一个请求(应该返回一个空白页)httpClient.execute(httpGet);被永久阻止,永远不会回来或者都不会抛出任何异常.如果我设置连接请求超时,那么最后一次调用没有被阻止,并且没有说超时,但我没有理解为什么最后一次调用不起作用如果我从firefox RESTClient进行相同的最后一次调用它可以工作.请帮助.
我也尝试添加不同的日志级别System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");和其他日志来调试,但没有运气.
以下是我的代码.
private static Servers fetchServers(String token,String endpoint) throws Exception{
JsonReader jreader = null;
InputStreamReader isr = null;
CloseableHttpClient httpClient = null;
try{
URI uri = new URI(endpoint);
/** accepting all certificates */
httpClient = getSecuredHttpClient();
uri = new URIBuilder(uri)
.setParameter("limit", "1")//Page limit, for testing have kept just 1 since i have only 2 records.
.build();
HttpGet httpGet = new HttpGet(uri);
httpGet.setHeader(HTTP.CONTENT_TYPE, "application/json");
httpGet.setHeader("X-Auth-Token", token);
httpGet.setHeader("accept", "application/json");
httpGet.setHeader(HTTP.USER_AGENT, "python-neutronclient");
Servers cloudServers …Run Code Online (Sandbox Code Playgroud) java apache rest apache-httpcomponents apache-httpclient-4.x
我正在对kerberos认证的REST服务执行https请求.如果我使用keytab,一切都很好.但是,我要求我应该使用kerberos票证缓存文件,该文件是在使用其密码登录工作站时创建的.
我将用MY_DOMAINE.COM替换域名
所以,klist显示:
Ticket cache: FILE:/tmp/krb5cc_210007
Default principal: dragomira@MY_DOMAINE.COM
Valid starting Expires Service principal
05/15/18 07:21:51 05/15/18 17:21:51 krbtgt/MY_DOMAINE.COM@MY_DOMAINE.COM
renew until 05/22/18 06:18:22
Run Code Online (Sandbox Code Playgroud)
像这样使用卷曲可以正常工作:
curl -k --negotiate -u : 'my_url' -v
Run Code Online (Sandbox Code Playgroud)
现在,让我们回到代码.我的login.conf是这样的:
com.sun.security.jgss.login {
com.sun.security.auth.module.Krb5LoginModule required
client=TRUE
doNotPrompt=true
useTicketCache=true;
};
com.sun.security.jgss.initiate {
com.sun.security.auth.module.Krb5LoginModule required
client=TRUE
doNotPrompt=true
useTicketCache=true;
};
com.sun.security.jgss.accept {
com.sun.security.auth.module.Krb5LoginModule required
client=TRUE
doNotPrompt=true
useTicketCache=true;
};
Run Code Online (Sandbox Code Playgroud)
我的http客户端的相关java代码是针对kerberos的,它是:
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (chain, authType) -> true).build();
HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory()) …Run Code Online (Sandbox Code Playgroud) java kerberos apache-httpcomponents apache-httpclient-4.x apache-httpclient-5.x
我有一个依赖关系如下:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2</version>
<scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
httpcore.4.1.4当我部署httpcore.4.2一切正常时,这拉低了另一个引发ClassDefNotFound的依赖项。
我添加了两个依赖项,如下所示:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2</version>
<scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
并且仍然面临着同样的问题,即:MVN带来下来httpcore.4.1.2不httpcore.4.2
我该如何解决?
编辑:
添加;
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud) 在Apache HTTP Component 4类org.apache.http.impl.auth.BasicScheme中,我注意到了该方法:
public static Header authenticate(
final Credentials credentials,
final String charset,
final boolean proxy)
Run Code Online (Sandbox Code Playgroud)
不推荐使用以下信息:
/**
* Returns a basic <tt>Authorization</tt> header value for the given
* {@link Credentials} and charset.
*
* @param credentials The credentials to encode.
* @param charset The charset to use for encoding the credentials
*
* @return a basic authorization header
*
* @deprecated (4.3) use {@link #authenticate(Credentials, HttpRequest, HttpContext)}.
*/
@Deprecated
Run Code Online (Sandbox Code Playgroud)
但是,我没有看到解释如何从deprated函数迁移到新函数的文档.虽然已弃用的功能有效,但我宁愿以"正确"的方式做事.以下是我使用不推荐使用的函数的方法:
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("admin", "admin");
URI uriLogin …Run Code Online (Sandbox Code Playgroud) 如何使http组件中的调试日志记录静音?
09:23:22.145 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
09:23:22.145 [main] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
09:23:22.145 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://example.org:80][total kept alive: 1; route allocated: 1 of 100; total allocated: 1 of 200]
09:23:22.145 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://diagnostics-uat.corp.apple.com:80][total kept alive: 0; route allocated: 1 of 100; total allocated: 1 of 200]
09:23:22.145 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request POST /evt/detect HTTP/1.1
09:23:22.145 [main] DEBUG o.a.h.impl.execchain.MainClientExec …Run Code Online (Sandbox Code Playgroud) 我想从HttpComponent的 org.apache.http.client.HttpClient 创建WebClient以在异步操作中使用它。关于如何做到这一点的任何想法
java apache-httpcomponents spring-webflux apache-httpclient-5.x spring-webclient
如何在Java中使用HttpResponse处理下载?我向特定站点发出了HttpGet请求 - 该站点返回要下载的文件.我该如何处理这个下载?InputStream似乎无法处理它(或者我可能以错误的方式使用它.)
我们使用 org.apache.http.client.HttpClient 库从我们的 Web 服务访问其他 Web 服务。
HttpRequestBase requestBase = <set uri>
httpClient.execute(requestBase);
Run Code Online (Sandbox Code Playgroud)
现在在某些时候,会发生这种异常:
*
Caused by: java.lang.InterruptedException: Operation interrupted
at org.apache.http.pool.PoolEntryFuture.await(PoolEntryFuture.java:142) ~[httpcore-4.4.4.jar:4.4.4]
at org.apache.http.pool.AbstractConnPool.getPoolEntryBlocking(AbstractConnPool.java:306) ~[httpcore-4.4.4.jar:4.4.4]
at org.apache.http.pool.AbstractConnPool.access$000(AbstractConnPool.java:64) ~[httpcore-4.4.4.jar:4.4.4]
at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:192) ~[httpcore-4.4.4.jar:4.4.4]
at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:185) ~[httpcore-4.4.4.jar:4.4.4]
at org.apache.http.pool.PoolEntryFuture.get(PoolEntryFuture.java:107) ~[httpcore-4.4.4.jar:4.4.4]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:276) ~[httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:263) ~[httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:190) ~[httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) ~[httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) ~[httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ~[httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) ~[httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) ~[httpclient-4.5.2.jar:4.5.2]
Run Code Online (Sandbox Code Playgroud)
*
有时会出现这个这个
*
Caused by: org.apache.http.impl.execchain.RequestAbortedException: Request aborted
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:193) ~[httpclient-4.5.2.jar:4.5.2]
at …Run Code Online (Sandbox Code Playgroud)