Comments (7)
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.
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.
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.
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.
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.
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.
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)
- Unable to use in new Android Project HOT 1
- Could not find package library
- AndroidNetworking.initialize(getApplicationContext()); Not working HOT 14
- Could not find com.amitshekhar.android:android-networking:1.0.2. HOT 5
- https://github.com/MindorksOpenSource/android-mvp-architecture
- Seri
- Lib is missing? Can't fetch v1.0.2 with gradle. See screenshot. HOT 1
- Failed to resolve: HOT 11
- Error building project HOT 4
- Networking
- ANRequest unregister `requestListener` HOT 1
- Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'. HOT 8
- How can I get the Body Parameters sent with request.
- i cannot import AndroidNetworking Class HOT 2
- AndroidNetworking class is not being imported HOT 4
- Can we get an Androidx Update to this?
- Repository down?
- I'm getting this error Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
- Regarding Fast Android Networking latest features support and new update HOT 2
- Failed to resolve HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fast-android-networking.