【发布时间】:2019-03-18 10:23:53
【问题描述】:
我正在开发一个应用程序,我可以在其中找到汽车的起点和目的地并将其发送到服务器。
我知道如何使用 volley 发送字符串,但是我发现很难以 JSON 格式发送数据。
部分代码如下:
b
tnFindPath.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RequestQueue queue = Volley.newRequestQueue(MapsActivity.this);
String url = "http://192.168.43.162:8080/";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
//adding parameters to the request
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("origin", etOrigin.getText().toString());
params.put("destination", etDestination.getText().toString());
return params;
}
};
// Add the request to the RequestQueue.
queue.add(stringRequest);
【问题讨论】:
标签: android json android-studio post android-volley