koush / AndroidAsync

Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.
Other
7.51k stars 1.56k forks source link

http server POST aplication/xml request.body().get() null #677

Closed Sergeant61 closed 4 years ago

Sergeant61 commented 4 years ago

Hello, I installed an http server. I have a camera that sends data and it sends data in application/xml format. But request.body(). get(). it is not always null. Can you help me with this ?

My Post Request :

image

My code:

`server.post("/mod1", new HttpServerRequestCallback() { @SuppressLint("SetTextI18n") @Override public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) { if (mod == 0) { SimpleXmlPullApp simpleXmlPullApp = new SimpleXmlPullApp(); Map<String, String> map = null;

                //String sbody = body.parse(new );

                try {

                    map = simpleXmlPullApp.xmlParse(request.getBody().toString());
                    Utility.getInstance().log(map);
                } catch (XmlPullParserException | IOException e) {
                    e.printStackTrace();
                    Utility.getInstance().log("PARSE ERROR: " + e.getMessage());
                }

                if (map != null) {

                    final String enter = map.get("enter");
                    final String exit = map.get("exit");

                    if (enter != null && exit != null) {

                        if (isSend)
                            dataSendApi(map);

                        Thread thread1 = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        int Ienter = Integer.parseInt(enter);
                                        int Iexit = Integer.parseInt(exit);

                                        tv_entry.setText((Ienter - Iexit) + "");
                                        tv_pass.setText((Integer.parseInt(max_entry) - (Ienter - Iexit)) + "");

                                        passControl(tv_pass.getText().toString());

                                        Utility.getInstance().log("Value write  " + max_entry + " " + Ienter + " " + Iexit);

                                    }
                                });
                            }
                        });

                        thread1.start();

                    } else {
                        Utility.getInstance().log("enter: " + enter + " --- " + " exit: " + exit);
                    }
                }
            } else {
                Utility.getInstance().log("Cihazdan veri geliyor ancak mod 1 seçili değil.");
            }
            response.end();
        }
    });`
Sergeant61 commented 4 years ago

Hello I found the solution.

request.setDataCallback(new DataCallback() { @Override public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) { Utility.getInstance().log("PARSE ERROR: " + bb.get()); Utility.getInstance().log("PARSE ERROR: " + bb.readString()); } });