How to post JSON to a REST webservice in codenameone

一曲冷凌霜 提交于 2019-12-08 00:21:24

postResponse() is invoked after the process completes. Not related to post itself. You want to override buildRequestBody which executes before. If I understand correctly you want the entire body to be the JSON and not an argument named "body" which is what you did...:

ConnectionRequest post = new ConnectionRequest(){
    @Override
    protected void buildRequestBody(OutputStream os) throws IOException {
        os.write(json.toString().getBytes("UTF-8"));
    }

    @Override
    protected void readResponse(InputStream input) throws IOException {
       // parse response data
    }
};
post.setUrl("http://localhost:8093/halimatbank/cbs/staff");
post.setPost(true);
post.setContentType("application/json");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!