Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
LoopJ AndroidAsyncHttp库:服务器接收空参数_Android_Android Async Http - Fatal编程技术网

LoopJ AndroidAsyncHttp库:服务器接收空参数

LoopJ AndroidAsyncHttp库:服务器接收空参数,android,android-async-http,Android,Android Async Http,我在一个Android项目中使用LoopJ AndroidAsyncHttp库,但是当我试图在服务器端获取参数时,我得到了null。我试着使用PHP和Java,得到了同样的结果。我100%确信我的服务器端工作正常,因为我使用了postman chrome插件,它可以工作: 客户端代码: public void sendRequest(View v) { try { AsyncHttpClient client = new AsyncHttpClient();

我在一个Android项目中使用LoopJ AndroidAsyncHttp库,但是当我试图在服务器端获取参数时,我得到了null。我试着使用PHP和Java,得到了同样的结果。我100%确信我的服务器端工作正常,因为我使用了postman chrome插件,它可以工作:

客户端代码:

public void sendRequest(View v) {

    try {

        AsyncHttpClient client = new AsyncHttpClient();

        // HashMap<String, String> paramsMap = new HashMap<String,
        // String>();
        // paramsMap.put("action", "Action Value");
        // RequestParams params = new RequestParams(paramsMap);

        RequestParams params = new RequestParams();
        params.add("action", "insert");

        AsyncHttpResponseHandler handler = new AsyncHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, Header[] headers,
                    byte[] body) {
                System.out.println("On Success --> Status Code: "
                        + statusCode);
                String response = new String(body);
                System.out.println("On Success --> Response: " + response);
            }

            @Override
            public void onFailure(int statusCode, Header[] headers,
                    byte[] body, Throwable error) {
                System.out.println("On Failure --> Status Code: "
                        + statusCode);
            }
        };

        String url1 = "http://192.168.1.9:8080/Tester";
        String url2 = "http://192.168.1.6/test";
        System.out.println("--->>> Params: " + params.toString());
         client.post(url1, params, handler);


    } catch (Exception e) {
        System.out.println("--> Exception: " + e.getMessage());
    }
}
服务器代码Java:

受保护的无效processRequestHttpServletRequest请求,HttpServletResponse响应 抛出ServletException、IOException{

    System.out.println("------->>> " + request.getParameter("action"));
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet FrontEndController</title>");            
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet FrontEndController at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

您是否尝试过将ProcessRequest更改为doPost…实际上,doPost/doGet都调用ProcessRequest,尽管我使用的是client.post,但只调用了doGet???