简体   繁体   中英

Android Volley: Cannot pass data to server

I am trying to create a simple registration page for my android app. I am passing parameters with URL String and Storing those parameters in Database. Whenever i try to use string directly in browser the data is added to database without any error. However, When i try to pass data from Android Volley i am getting HTTP Error 409.

I have checked everything and still confused why this error is appearing only when i try to run url string from android app.

URL String:-

http://myurl.com/api/register.php?name=ahmed&email=obaid.ahmed@gmail.com&password=12345&membertype=Artist&joindate=24-Feb-2019

Java Code:-

       JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, urlFinal, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    // display response
                    Log.d("Response", response.toString());
                    uploadImageToServer();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d("Error.Response", error.toString());
                    hideDialog();
                }
            }
    );

First you need to understand about 409,

Explain here :- https://httpstatuses.com/409

And try to solve this on Server side where this Conflict issue occur.

And I recommend you to use URL Encoding before sending things in url, Which is perform by : Either by,

  String query = URLEncoder.encode("apples oranges", "utf-8");
  String url = "http://stackoverflow.com/search?q=" + query;

or By

  String uri = Uri.parse("http://...")
            .buildUpon()
            .appendQueryParameter("key", "val")
            .build().toString();

Which make your URL more compatible.

Or for More Better ways, There is an Library which i personally recommend to any android developer who love Light weight Volley for Api Integrations.

https://github.com/Lib-Jamun/Volley

dependencies {
   compile 'tk.jamun:volley:0.0.4'
}

Cool Coding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM