Reputation: 3
class test2 : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test2)
connect()
}
fun connect(){
val queue = Volley.newRequestQueue(this)
val url = "https://www.example.com/Register.php"
val params = HashMap<String,String>()
params["abc"] = "parm1"
params["def"] = "parm2"
params["ghi"] = "parm3"
val stringRequest = StringRequest(Request.Method.POST, url,
Response.Listener<String> { response ->
text_test.text = "Response is: $response"
},
Response.ErrorListener { text_test.text = "That didn't work! " })
queue.add(stringRequest)
}
}
The parameters should be in "param1=data1¶m2=data2¶m3=data3"
format
I can send data in postmen using form-data
Any idea how i can send the data from my code?
Seriously please send help this is my second time asking
Here is the image for postman https://ibb.co/SQgG72W
Upvotes: 0
Views: 581
Reputation: 151
You have to override getParams
Method. In that you can pass your params you want to send to the server
StringRequest sr = new StringRequest(Request.Method.POST, "http://headers.jsontest.com/",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("HttpClient", "success! response: " + response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("HttpClient", "error: " + error.toString());
}
})
{
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("user","YOUR USERNAME");
params.put("pass","YOUR PASSWORD");
return params;
}
};
Upvotes: 2