Problems using PUT method with Restful api

24 views
Skip to first unread message

rdvg...@gmail.com

unread,
Jun 12, 2021, 2:39:21 AM6/12/21
to CodenameOne Discussions
Hi,
I am trying to update a record by sending parameters to a Webservice. When I run it it returns the code 400 (Bad Request).
The method used is the following:
    public static Response aceptarCarga(Long cargaId, Long fecha) {
        Response<String> r = Rest.put(SERVER_URL + "ws_carga1/ws_carga1.php").
                header("token", UsuarioService.getToken()).
                queryParam("carga_id", Long.toString(cargaId)).
                queryParam("fecha", Long.toString(fecha)).
                queryParam("accion", "aceptar_carga").
                getAsString();
        return r;
    }
Provide the same parameters sent through Postman and they run correctly.
I include an image that returns the correct SQL to me via Postman
Postman.png

Shai Almog

unread,
Jun 12, 2021, 9:38:36 PM6/12/21
to CodenameOne Discussions
Hi,
PUT defaults to sending parameters as POST within the Rest API. I'll add a way to override that behavior with a postParameters(false) method. This will be there next week.
A potential workaround might be to use a "hack" like this:
        Response<String> r = Rest.put(SERVER_URL + "ws_carga1/ws_carga1.php?carga_id=" + Long.toString(cargaId) + "&fecha=" + Long.toString(fecha) + "&accion=aceptar_carga")).
                header("token", UsuarioService.getToken()).
                getAsString();

rdvg...@gmail.com

unread,
Jun 13, 2021, 9:31:23 AM6/13/21
to CodenameOne Discussions
Hi,

Thank you very much Mr. Shai, I have other methods in my application that they use in the PUT method and I need to send information through the body. In this scenario it also sends me error. Have another trick to move forward?

rdvg...@gmail.com

unread,
Jun 13, 2021, 10:14:04 AM6/13/21
to CodenameOne Discussions
Hi,
Excuse me, if it works fine when I send information through the body.

Shai Almog

unread,
Jun 13, 2021, 9:36:20 PM6/13/21
to CodenameOne Discussions
In the screenshot you posted it looks like you passed the parameters in the URL.
Reply all
Reply to author
Forward
0 new messages