Luis Leal
Luis Leal

Reputation: 3514

codenameone REST API POST request body

Im trying to call a POST method from a REST API on AWS API Gateway.The API is correctly called from command line using curl(for POST)and the browser using GET so i know its working fine, but i cant seem to find the correct way to call POST method on codename one using ConnectionRequest class, reading the documentation theres addArgument() and setRequestBody() and they say , they are exclusive, so i tried both , but my results are:

Im using request.setPost(true); but theres also setHttpMethod(String value); so i am not sure if i am doing it right.

Whats the correct way of calling a POST REST and send it parameters? Is there any way to debug the request being sent? like printing the equivalent CURL call or somethint like that? Or theres any way to perform the CURL request directly on CN1 ?

Upvotes: 1

Views: 595

Answers (2)

Luis Leal
Luis Leal

Reputation: 3514

Answering my question,after Shai Almong help, and some testing, the correct way its(i was missing setContentType call) :

setPost(true);
setContentType('application/json');
setRequestBody("parameters in json format");

Upvotes: 1

Shai Almog
Shai Almog

Reputation: 52770

This isn't the exact same thing as it's a multipart upload but I have working AWS upload code here, if you update the question (and comment below) I can include code to do the exact curl request in Codename One.

As to the question calling setPost(true) is enough as it will set the post method implicitly. The http method is useful if you want to do something like PUT.

Picking request body vs. argument depends on the type of request you have.

Upvotes: 1

Related Questions