【问题标题】:How to send a cookie along with HttpGet in Java如何在 Java 中与 HttpGet 一起发送 cookie
【发布时间】:2010-08-01 19:10:59
【问题描述】:

我正在尝试将 cookie 与我的 HttpGet 请求一起发送,但每次我尝试都无法成功发送它。我也尝试直接修改标题,这是我的代码:

DefaultHttpClient httpClient = new DefaultHttpClient();  

CookieStore store = new BasicCookieStore();
store.addCookie(MyCookieStorageClass.getCookie());
httpClient.setCookieStore(store);

HttpGet httpGet = new HttpGet("http://localhost/);     

try {
    // Execute HTTP Get Request  
    HttpResponse response = httpclient.execute(httpGet);  
    String responseData = ResponseHandler.getResponseBody(response);
} catch (IOException e) {
    e.printStackTrace();
}

【问题讨论】:

  • 这实际上是 HttpClient 4.0.1 的正确实现,我刚刚没有得到正确的 cookie。

标签: java android cookies httpclient


【解决方案1】:

这实际上是 HttpClient 4.0.1 的正确实现,我刚刚没有得到正确的 cookie。

【讨论】:

    【解决方案2】:

    您的MyCookieStorageClass.getCookie() 方法是否返回具有正确域和路径属性的 Cookie?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      相关资源
      最近更新 更多