سؤال

I am trying to use the android-async-http library http://loopj.com/android-async-http/

It suggests to use this code:

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);
        }
    });
}
}

But now my issue is that I need to get the response object and I also need to get hold of the http header .

How can I get the http header ?

هل كانت مفيدة؟

المحلول

@Zapnologica, it seems, that author of library provided changes based on this pull request: https://github.com/loopj/android-async-http/pull/170 But it is not released yet, at least latest available .jar version of library is 1.4.3 and it does not include these changes, unfortunately. The only option we may try to use is cloning/forking git repo and including its sources into your project.

UPDATE: Seems library will soon be added to maven central repo, but at least now I was able to add 1.4.4 SNAPSHOT build using gradle for my project with such config changes:

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

And then in dependencies section:

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

Since then I have such a methods for AsyncHttpResponseHandler available for overriding:

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

And:

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

UPD: Here is the link for issue to add lib to maven: https://github.com/loopj/android-async-http/issues/168

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top