简体   繁体   中英

Unable to post data to api from android using Volley

I want to register the user using post method. here is the API link:

`http://125.62.194.181/SmartTrackerAPI/api/User/SignUp/UserName/EmpId/Email/Mobile/Password`

I am new to JSON. I understood how to get data from JSON but when it comes to POST method, I am not getting how to do?

Need help, Thank you.

The data sent to the server with POST is stored in the request body of the HTTP request:

Here Is A Sample How You Can Do Using Volley It:-

    String url = "YOUR URL";
    RequestQueue queue = Volley.newRequestQueue(this);//Creating The Request Queue
    StringRequest postRequest = new StringRequest(Request.Method.POST/*Setting The Method As Post*/, url/*Passing The Url Of Your API*/, 
        new Response.Listener<String>() 
        {
            @Override
            public void onResponse(String response) {
                // response
                Log.d("Response", response);
           //Here You Will Get Your JSON as response.
            }
        }, 
        new Response.ErrorListener() 
        {
             @Override
             public void onErrorResponse(VolleyError error) {
                 // error
                 Log.d("Error.Response", response);
             //Here You Will Get Your Error related to your Request.
           }
        }
    ) {     
        @Override
        protected Map<String, String> getParams() 
        {  
                Map<String, String>  params = new HashMap<String, String>();  
                params.put("name", "Alif");  
                params.put("domain", "http://itsalif.info");//Puting The  Parameters In Map To Pass It To The API.

                return params;  
        }
    };
    queue.add(postRequest);

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