2016-09-16 9 views
0

私がアンドロイドアプリでこのような要求を行うために探していますねえ:ボレーでPOSTリクエストを行う

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); 
} 

これは、ここから取得されます:

curl --header "Content-Type: text/plain" --request POST --data "ON" http://example.com:8080/rest/items/wakeup 

は、これまでのところ、私は、これは持っています: https://www.simplifiedcoding.net/android-volley-post-request-tutorial/ 誰かがこの仕事をする方法を理解するのに手伝ってもらえますか?私はAAAAAAとBBBBBBがどこに行くのかを知っているが、文字列 "ON"をどのように送ることができるのかは分からない。あなたは、文字列「ON」で

+0

何を意味するのですか?あなたはそれを明確にしていただけますか?これにパラメータを送る方法を知りたいですか? –

+1

2番目の例の[回答はこちら](http://stackoverflow.com/a/26270185/1270789)を参照してください。 getParams()ではなく 'getBody()'の 'return String(" ON ")、getBytes(); –

+0

check http://stackoverflow.com/questions/31552242/sending-http-post-request-with-android –

答えて

0

オープンサーバのポート80に接続すると、このテキストを送信する(あなたがに投稿したいファイルをi.php置き換え)

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 
+0

アンドロイドでソケットを使用するコードはどこにでもありますhttp://androidsrc.net/android-client-server-using-sockets-client-implementation/ –

関連する問題