Hey I am looking to do a request like this in my android app:
curl --header "Content-Type: text/plain" --request POST --data "ON" http://example.com:8080/rest/items/wakeup
So far I have this:
String url = "http://example.com:8080/rest/items/wakeup";
StringRequest MyStringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MjpegActivity.this,response,Toast.LENGTH_LONG).show();
//This code is executed if the server responds, whether or not the response contains data.
//The String 'response' contains the server's response.
}
},
new Response.ErrorListener() { //Create an error listener to handle errors appropriately.
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MjpegActivity.this,error.toString(),Toast.LENGTH_LONG).show();
//This code is executed if there is an error.
}
}){
@Override
protected Map<String, String> getParams() {
Map<String, String> MyData = new HashMap<String, String>();
MyData.put("AAAAAA", "BBBBBB"); //Add the data you'd like to send to the server.
return MyData;
}
};
RequestQueue MyRequestQueue = Volley.newRequestQueue(this);
MyRequestQueue.add(MyStringRequest);
}
This is taken from here: https://www.simplifiedcoding.net/android-volley-post-request-tutorial/ Can someone help me figure out how to make this work? I know that the data I send goes where AAAAAA and BBBBBB are but I dont really understand how I can just send the string "ON".