Giter Site home page Giter Site logo

Comments (7)

paulpv avatar paulpv commented on April 29, 2024

FYI, here is my working Volley code:

mRequestQueue.add(new JsonObjectRequest(uri.toString(), jsonObjectBody, new Listener<JSONObject>()
{
    @Override
    public void onResponse(JSONObject response)
    {
        Log.i(TAG, "requestJSONObject(tag=" + tag + ") onResponse: response=" + response);
        //...
    }
}, new ErrorListener()
{
    @Override
    public void onErrorResponse(VolleyError error)
    {
        Log.w(TAG, "requestJSONObject(tag=" + tag + ") onError: error=" + error);
        //...
    }
})
{
    @Override
    public String getBodyContentType()
    {
        return "application/json; charset=utf-8";
    }

    @Override
    public Map<String, String> getHeaders()
            throws AuthFailureError
    {
        Map<String, String> headers = super.getHeaders();
        if (headers == null || headers.equals(Collections.emptyMap()))
        {
            headers = new HashMap<>();
        }

        headers.put("User-Agent", mUserAgent);
        headers.put("APP-ID", mAppId);
        headers.put("Debug", "true");

        return headers;
    }
});

from fast-android-networking.

amitshekhariitbhu avatar amitshekhariitbhu commented on April 29, 2024

I just created the same situation to test it.

API - which require both and in JSONObject. otherwise it send error with error body as bad parameter

When I make request it is working perfectly. Still trying to figure out the problem you are facing.

        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("firstname", "Amit");
//            jsonObject.put("lastname", "Shekhar");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        AndroidNetworking.post("https://fierce-cove-29863.herokuapp.com/createAnUser")
                .addJSONObjectBody(jsonObject)
                .setTag(this)
                .setPriority(Priority.LOW)
                .build()
                .getAsOkHttpResponseAndJSONObject(new OkHttpResponseAndJSONObjectRequestListener() {
                    @Override
                    public void onResponse(Response okHttpResponse, JSONObject response) {

                    }

                    @Override
                    public void onError(ANError error) {

                    }
                });

Thanks
Amit Shekhar

from fast-android-networking.

paulpv avatar paulpv commented on April 29, 2024

Thanks for the response.
Can you clarify your statement?
What causes "otherwise it send error with error body as bad parameter", or is everything "it is working perfectly"?

from fast-android-networking.

amitshekhariitbhu avatar amitshekhariitbhu commented on April 29, 2024

When I make request with correct data, it is giving me in onResponse method

 jsonObject.put("firstname", "Amit");
 jsonObject.put("lastname", "Shekhar");

When I make request with wrong data, it is giving me in onError method with errorBody as {"error":"bad parameter"}

 jsonObject.put("firstname", "Amit");
// not setting lastname.

from fast-android-networking.

paulpv avatar paulpv commented on April 29, 2024

That sounds to me like a server side logic choice that is probably by design.
What happens if you post a single field using Volley?
I still can't figure out why Volley works, but AN doesn't. :/

from fast-android-networking.

paulpv avatar paulpv commented on April 29, 2024

Today's investigation is leading me to believe that the problem I am seeing is related to the GzipRequestInterceptor.

OkHttpClient.Builder builder = new OkHttpClient.Builder();
//builder.addInterceptor(new GzipRequestInterceptor());
if (BuildConfig.DEBUG)
{
    builder.addNetworkInterceptor(new StethoInterceptor());
}
OkHttpClient httpClient = builder.build();
AndroidNetworking.initialize(applicationContext, httpClient);

When I comment out the GzipRequestInterceptor line, my server logic seems to work.
I can confirm that my server used to be set up to accept gzip encoding, but from looking at the headers in my first entry above, the server isn't responding w/ gzip, so perhaps it got disabled.
I will confirm w/ my web dev as soon as he recovers from last night's US election...

from fast-android-networking.

paulpv avatar paulpv commented on April 29, 2024

Yup!
The problem is with adding GzipRequestInterceptor when a server have gzip enabled.
gzip capabilities need to be tested as supported on the server before enabled.
Which begs a general question, which may end up being an okhttp question:
How should this negotiation be tested and enabled on a per-server basis?

from fast-android-networking.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.