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 –