Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom content-type #14

Closed
willemevenwel opened this issue Aug 19, 2016 · 8 comments
Closed

Add support for custom content-type #14

willemevenwel opened this issue Aug 19, 2016 · 8 comments

Comments

@willemevenwel
Copy link

Thanks for great library.

Please add support to add custom content-type when using RequestBuilder. It would be nice to be able to add bytes as the body, then custom content-type.

Something like:

AndroidNetworking.post(url).addByteBody(bytes).addContentType("application/json")

Regards,

Willem

@amitshekhariitbhu
Copy link
Owner

@willemevenwel : added in development branch

@willemevenwel
Copy link
Author

Thanks, great work. Tested and working. Will provide more feedback if more feedback comes up.

@nithingkamath
Copy link

Hi, Thanks for this awesome library. I have one question. How to get the status code from the response.? I didn't find any way to get that.

@amitshekhariitbhu
Copy link
Owner

@nithingkamath : You are welcome.

to get the response code you can call response.code() if you are using getAsOkHttpResponse.

And also like this :
We have a callback method onError(ANError error).

  if (error.getErrorCode() != 0) {
     // received error from server
     // error.getErrorCode() - the error code from server
     // error.getErrorBody() - the error body from server
     // error.getErrorDetail() - just an error detail
     Log.d(TAG, "onError errorCode : " + error.getErrorCode());
     Log.d(TAG, "onError errorBody : " + error.getErrorBody());
     Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());                            
    } else {
     // error.getErrorDetail() : connectionError, parseError, requestCancelledError
     Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
    }                    

@tausiq
Copy link

tausiq commented Sep 3, 2016

@amitshekhariitbhu
Could you please provide support that OkHttpResponse object will get passed in onResponse method of ParsedRequestListener interface?
In that case, we can get the status code from OkHttpResponse object and still enjoying the parsed object in onResponse. Thanks in advance!

@amitshekhariitbhu
Copy link
Owner

As of I have done to get OkHttpResponse in Development as getAsOkHttpResponse

As of now I have uploaded it on beta.

So please compile using the below link.

compile 'com.amitshekhar.android:android-networking:0.2.0-beta-0

.getAsOkHttpResponse(new OkHttpResponseListener() {
    @Override
    public void onResponse(Response response) {
        if (response != null) {
            // we can find header also like response.headers() or anything than can be obtained from OkHttpResponse
            if (response.isSuccessful()) {
                Log.d(TAG, "response is successful");
                try {
                    Log.d(TAG, "response : " + response.body().source().readUtf8());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                Log.d(TAG, "response is not successful");
            }
        } else {
            Log.d(TAG, "response is null");
        }
    }

    @Override
    public void onError(ANError error) {
        Utils.logError(TAG, error);
    }
});

I think you are telling to provide both parseResponse and OkHttpResponse in a response listener

@tausiq
Copy link

tausiq commented Sep 3, 2016

Thank you for your quick reply!

I am aware of the OkHttpResponseListener functionality. What I requested, can be summarized like below,

.getAsParsed(new TypeToken<User>() {}, new ParsedRequestListener<User>() {
    @Override
    public void onResponse(Response response, User user) {
        // we can find header like response.headers()
        // we can get user as parsed
    }

    @Override
    public void onError(ANError anError) {
        // handle error
    }
}); 

@amitshekhariitbhu
Copy link
Owner

amitshekhariitbhu commented Sep 3, 2016

I will try to add this as soon as possible.

Thanks
Amit Shekhar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants