相关疑难解决方法(0)

使用HttpRequest.execute()的异常:无效使用SingleClientConnManager:仍然分配了连接

我正在使用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)

为什么我下面的代码会尝试获取连接?

java httpclient google-api-java-client

80
推荐指数
4
解决办法
6万
查看次数

HttpClient警告:Cookie被拒绝:非法域属性

我正在使用HttpClient最新版本(4.x).而现在我正在尝试做一个GET请求.我刚刚发布了一个Get请求.

这是我的代码;

public class Poster {

    static boolean routing1 = true, routing2 = true;
    static int counter1 = 0, counter2 = 0;
    DefaultHttpClient oHtp = null;
    HttpGet oHGet = null;
    HttpResponse oHRes = null;


    private void test(String fullAddress) throws Exception {
        oHtp = new DefaultHttpClient();
        oHGet = new HttpGet(fullAddress);

        HttpResponse response = oHtp.execute(oHGet);
        System.out.print(response.getStatusLine());

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            entity = new BufferedHttpEntity(entity);
            //  System.out.println(EntityUtils.toString(entity));
            System.out.print("\t entity is retrieved... ");
        }


        oHtp.getConnectionManager().shutdown();
    }
}
Run Code Online (Sandbox Code Playgroud)

我只是很好地执行它.首先是

new …
Run Code Online (Sandbox Code Playgroud)

java cookies warnings httpclient

22
推荐指数
3
解决办法
5万
查看次数

如何强制Java的HttpClient接受无效的cookie?

我正在编写一个登录到WordPress的脚本,但是,HttpClient的cookie策略将WordPress设置的cookie识别为无效:

May 17, 2009 12:07:43 PM org.apache.commons.httpclient.HttpMethodBase processCookieHeaders
WARNING: Cookie rejected: "$Version=0; wordpress_dce2080bc042b2e639e4f5b3b704aa43=admin%7C1243786064%7C4c56aef46b1210d3d43d8b829fdf4d9a; $Path=/wp-content/plugins". Illegal path attribute "/wp-content/plugins". Path of origin: "/wp-login.php"
May 17, 2009 12:07:43 PM org.apache.commons.httpclient.HttpMethodBase processCookieHeaders
WARNING: Cookie rejected: "$Version=0; wordpress_dce2080bc042b2e639e4f5b3b704aa43=admin%7C1243786064%7C4c56aef46b1210d3d43d8b829fdf4d9a; $Path=/wp-admin". Illegal path attribute "/wp-admin". Path of origin: "/wp-login.php"
Run Code Online (Sandbox Code Playgroud)

没有cookie支持,脚本无法登录.我怎么能绕过这个?

(使用HttpClient 3.1)

java cookies wordpress httpclient

3
推荐指数
1
解决办法
2万
查看次数