2013-08-05 31 views
0

我試圖使用Android系統的異步HTTP庫http://loopj.com/android-async-http/Android的異步HTTP庫GET HTTP響應頭

它建議使用此代碼:

public void getPublicTimeline() throws JSONException { 
    TwitterRestClient.get("statuses/public_timeline.json", null, new JsonHttpResponseHandler() { 
     @Override 
     public void onSuccess(JSONArray timeline) { 
      // Pull out the first event on the public timeline 
      JSONObject firstEvent = timeline.get(0); 
      String tweetText = firstEvent.getString("text"); 

      // Do something with the response 
      System.out.println(tweetText); 
     } 
    }); 
} 
} 

但現在我的問題是我需要獲取響應對象,並且我還需要獲取http標頭。

如何獲取http標頭?

+0

所有我需要的是能夠從響應訪問HTTP標頭。但是使用這個庫需要你給它一種HttpResponseHandler – Zapnologica

回答

1

@Zapnologica看來,基於此要求拉庫所提供的更改作者:https://github.com/loopj/android-async-http/pull/170 但尚未發佈,圖書館至少最新可用的.jar版本是1.4.3,它不包括這些變化,不幸的是。 我們可能嘗試使用的唯一選擇是克隆/分配git repo並將其源代碼包含到您的項目中。

UPDATE: 似乎庫將很快加入到Maven中央回購,但至少現在我能有這樣的配置的變化添加使用gradle這個1.4.4快照建立我的項目:

repositories { 
    ... 
    //android-async-client repo 
    maven { 
     url "https://oss.sonatype.org/content/repositories/snapshots/" 
    } 
} 

然後在依賴部分:

compile 'com.loopj.android:android-async-http:1.4.4-SNAPSHOT' 

從那時起,我對AsyncHttpResponseHandler可用這樣的方法覆蓋:

@Override 
public void onSuccess(int statusCode, Header[] headers, String content) { 
    super.onSuccess(statusCode, headers, content); 
} 

和:

@Override 
protected void sendResponseMessage(HttpResponse response) { 
    super.sendResponseMessage(response); 
} 

UPD:這裏是鏈接的問題添加的lib到Maven:https://github.com/loopj/android-async-http/issues/168