0

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".

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137

1 Answers1

0

Open a connection to the server port 80 and send this text( replace i.php with your file you want to post to )

POST /i.php HTTP/1.1
Host: denta.dev:8081
User-Agent: curl/7.47.0
Accept: */*
Content-Type: text/plain
Content-Length: 2

ON
CGeorgian
  • 551
  • 6
  • 10
  • Code to use Sockets in android is everywhere , example http://androidsrc.net/android-client-server-using-sockets-client-implementation/ – CGeorgian Sep 16 '16 at 06:09