2

This is my android code

 JSONObject params = new JSONObject(); params.put("username","[email protected]"); params.put("password","hellothere"); JsonObjectRequest loginRequest = new JsonObjectRequest( Request.Method.POST, "http://192.168.2.67/tmp/test.php", params, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { Log.d("",""); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Log.d("",""); } }); requestQueue.add(loginRequest); 

The server code in php

 <?php $usr = $_REQUEST['username']; $pwd = $_REQUEST['password']; $resp[$usr]=$pwd; echo json_encode($resp); ?> 

the response i'm getting is {"":null}

I tried with apache http cleint and it worked prferectly is there any way i can do this with volley?

1

2 Answers 2

6

To send parameters in request body you need to override either getParams() or getBody() method of the request classes

Source: Asynchronous HTTP Requests in Android Using Volley

Sign up to request clarification or add additional context in comments.

Comments

2
@Override protected Map<String, String> getParams() { Map<String, String> params = new HashMap<String, String>(); params.put("username", "SomeUser"); params.put("password", "blabla"); return params; } 

This is the way you should override getParams() method.

5 Comments

Are you sure my friend? I have been using this approach for lots and lots of POST requests. It works fine.
Do you return JSONOrject or a String? I use CustomVolleyRequest posted by someone in stackoverflow. It works fine
it's the other way around, it's called on POST requests but not on GET requests.
where is this custom volley request? @BalaVishnu
StringRequest lets u specify whether post or get. It is under Volley toolbox

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.