我正在使用google-api-client-java 1.2.1-alpha来执行POST请求,并在执行()HttpRequest时获得以下stacktrace.
它在我捕获并忽略从先前的POST到同一URL的403错误后立即发生,并重新使用传输进行后续请求.(它在一个循环中插入多个条目到同一个ATOM提要).
在403之后,我应该做些什么来"清理"?
Exception in thread "main" java.lang.IllegalStateException: Invalid use of SingleClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.
at org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConnManager.java:199)
at org.apache.http.impl.conn.SingleClientConnManager$1.getConnection(SingleClientConnManager.java:173)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:390)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
at com.google.api.client.apache.ApacheHttpRequest.execute(ApacheHttpRequest.java:47)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:207)
at au.com.machaira.pss.gape.RedirectHandler.execute(RedirectHandler.java:38)
at au.com.machaira.pss.gape.ss.model.records.TableEntry.executeModification(TableEntry.java:81)
Run Code Online (Sandbox Code Playgroud)
为什么我下面的代码会尝试获取新连接?
我正在研究我们公司开发的应用程序.它使用Apache HttpClient库.在源代码中,它使用HttpClient类来创建连接到服务器的实例.
我想了解Apache HttpClient,我已经通过这组示例了解.所有示例都使用CloseableHttpClient而不是HttpClient.所以我认为CloseableHttpClient是一个扩展版本HttpClient.如果是这种情况,我有两个问题:
我正在使用org.apache.http,我有这个代码:
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse resp = client.execute(get);
HttpEntity entity = resp.getEntity();
InputStream input = entity.getContent();
...
//Read the bytes from input stream
Run Code Online (Sandbox Code Playgroud)
这是我用来通过Http下载文件的代码,我想取消连接(可能是用户选择的)什么是关闭连接的优雅方式.我找到了两种方法,两种都取消了下载.
我尝试捕获,所以没有错误,但没有抛出异常,有没有办法取消或中止连接?
什么是正确的方法呢?
在这里,我试图将一些数据从移动设备发送到服务器.首先,我必须登录服务器上的身份验证.然后在我通过POST请求发送数据后,我检查了这个相关的stackoverflow问题.HttpClient 4.0.1 - 如何释放连接?
我已经逐一尝试了所有这些方法.
1.EntityUtils.consume(实体);
2.is.close();
.response.getEntity()consumeContent(); //在那个consumeContent()中显示为Deprecated
post.abort();
这是我在pastebin链接中的详细代码,请检查一下.
这是程序流程.
首次登录称为"在此登录 我的登录请求"
登录后和发布之前的想法THIS方法被调用.
最后调用post idea方法.
但是logcat显示错误:
java.lang.IllegalStateException:无效使用BasicClientConnManager:仍然分配了连接.
确保在分配另一个连接之前释放连接
Run Code Online (Sandbox Code Playgroud)W/System.err( 2217): java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated. W/System.err( 2217): Make sure to release the connection before allocating another one. W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.conn.BasicClientConnectionManager.getConnection(BasicClientConnectionManager.java:161) W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.conn.BasicClientConnectionManager$1.getConnection(BasicClientConnectionManager.java:138) W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:455) W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:902) W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:801) W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:780) W/System.err( 2217): at com.rahul.cheerfoolz.api.util.postData(util.java:436) W/System.err( 2217): at com.rahul.cheerfoolz.postidea.idea.post_myidea_edit$Post_Idea.doInBackground(post_myidea_edit.java:354) W/System.err( …