0
嘿,我希望做這樣的請求,在我的Android應用程序:做一個POST請求與排球
curl --header "Content-Type: text/plain" --request POST --data "ON" http://example.com:8080/rest/items/wakeup
到目前爲止,我有這樣的:
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);
}
這是從這裏取: https://www.simplifiedcoding.net/android-volley-post-request-tutorial/ 有人可以幫我弄清楚如何使這項工作?我知道我發送的數據是在AAAAAA和BBBBBB的地方,但我真的不知道如何發送字符串「ON」。
你是什麼意思字符串「ON」位置(要張貼到您的文件替換i.php)?你能澄清一下嗎?你想知道如何發送參數到這個? –
請參閱[這裏的答案](http://stackoverflow.com/a/26270185/1270789),第二個例子。你可能只想爲'getBody()'返回String(「ON」)。getBytes();'而不是'getParams()'。 –
檢查http://stackoverflow.com/questions/31552242/sending-http-post-request-with-android –