I want to pass the following JSON object in a volley string request:
{
"command":"connect",
"port":"VIRTUAL",
"baudrate":115200,
"printerProfile":"_default",
"save":true,
"autoconnect":false
}
The response is 1
.
How can I implement this in Android studio using Kotlin and Volley?
RequestQueue queue = Volley.newRequestQueue(context);
StringRequest sr = new StringRequest(Request.Method.POST,URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//response
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//error
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("command","connect");
params.put("port","VIRTUAL");
params.put("baudrate", "115200");
params.put("save","true");
params.put("autoconnect","false");
return params;
}
};
queue.add(sr);
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.