I am using sitebricks-client to interact with REST APIs in Java. I need to do a POST with a non-empty body. How do I do that in sitebricks?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have not specified what kind of request body you are trying to post. If you are trying to send a String with a Content-Type of “text/plain”, then the following should work:
If you are trying to send data of a particular type that you have already serialized to a String, you can set the Content-Type header manually:
If you have a Map containing data that you would like to send to the server with a Content-Type of “application/json”, then something like this might be up your alley:
There are two important points to pay attention to in the examples above:
postmethod should be of the type passed to thetransportsmethod.overmethod determines the default value of the Content-Type header and the way in which the value passed to thepostmethod is serialized. The class should be a subclass ofcom.google.sitebricks.client.Transport, and you will probably want to choose one of the classes found in thecom.google.sitebricks.client.transportpackage.