【问题标题】:HttpRequestInterceptor in AndroidHttpClient. I'm confused!AndroidHttpClient 中的 HttpRequestInterceptor。我很困惑!
【发布时间】:2012-04-05 05:57:08
【问题描述】:

我在我的应用程序中使用 AndroidHttpClient。现在我需要对请求使用基本授权。

http://developer.android.com/reference/android/net/http/AndroidHttpClient.html

在文档中,他们说我可以使用 HttpRequestInterceptor,但我不知道该怎么做。没有添加此拦截器的方法。理想情况下,我想像他们在这里一样添加它: http://dlinsin.blogspot.com/2009/08/http-basic-authentication-with-android.html

有人知道为什么它对我不起作用或 Google 文档有误吗?

【问题讨论】:

标签: android http


【解决方案1】:

好的,这是不可能的,显然文档有误。必须使用普通的 HttpClient 才能使其工作。

【讨论】:

    【解决方案2】:

    我知道这个问题已经过时了,但是为了让遇到这个问题的人受益(就像我一样),您可以使用 HttpGet 对象自己滚动标题。像这样:

    httpGet.addHeader("Authorization", "Basic " + Base64.encode(username+":"+password));
    

    【讨论】:

      猜你喜欢
      • 2011-04-11
      • 2020-08-17
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多