处理 Web 服务器上由 Volley 生成的 POST 请求(字符串)

Handling POST request (String) generated by Volley at web server

我制作了一个 android 应用程序,它从 android 设备收集某些数据,然后 post 将它们作为字符串发送到 restful 网络服务器以接收相应的响应服务器。我正在使用 volley 方法来 POST 请求。我发送数据的代码如下:

RequestQueue queue = Volley.newRequestQueue(getBaseContext());
String url ="server url";

StringRequest stringRequest = new StringRequest(Request.Method.POST,url,
      new Response.Listener<String>() {
           @Override
           public void onResponse(String response) {
               showOutput("Response is: "+ response.substring(0,500));
           }
       },new Response.ErrorListener() {
           @Override
           public void onErrorResponse(VolleyError error) {
               showOutput("That didn't work!");
           }
       }){
           @Override
           protected Map<String, String> getParams() throws com.android.volley.AuthFailureError {
               Map<String, String> params = new HashMap<String, String>();
               params.put("query Type", "query Num");
               params.put("para1", "test data 1");
               params.put("para2", "test data 2");
               return params;
           }
       };

queue.add(stringRequest);

已编辑:

为了响应来自 android 设备的请求,我使用 tomcat 网络容器和球衣库创建了一个网络服务....使用 curl 我检查了服务器正在返回GETPOST 请求的字符串。但是,当我从 android 设备发送 POST/GET 查询时,响应出现在 ErrorListener 中。在服务器上处理 get/post 请求的 java class 以及我尝试过的各种选项如下:

@Path("/hello")
public class Hello {
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String sayPlainTextHello() {
  return "Hello GET String";
  } 
  @POST
  @Produces(MediaType.TEXT_PLAIN)
  public String post(@QueryParam("param1")String param1, @QueryParam("param2")String param2){
    String msg = param1+param2;
    return msg;
  }
/*
  public Response post(@QueryParam("param1")String param1, @QueryParam("param2")String param2){
    String msg = param1+param2;
    return Response.ok(msg).build();
  }
  public Response post(@QueryParam("param1")String param1, @QueryParam("param2")String param2){
    String msg = param1+param2;
    return Response.ok().build();
  }
  public Response post(@Context UriInfo ui){
  MultivaluedMap<String, String> queryParams =ui.getQueryParameters();
    String msg = param1+param2;
    Response r = null;
  return r;
  }
*/
}

我无法获得帮助:接收 android 设备在 POST 请求中发送的字符串,处理它们并发回字符串作为对 post 查询的响应。

如有任何帮助,我们将不胜感激...

抱歉这么笨....以上解决方案在重启时有效!!

android 设备正在接收 POST 查询的 post 响应字符串!!!