Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send x-www-form-urlencoded in a body of POST request using android annotations and resttemplate

my interface looks as follows:

@Rest(rootUrl = "https://myurl.com", converters = { GsonHttpMessageConverter.class })
public interface CommunicatonInterface
{
@Get("/tables/login")
public Login login(Param param);
public RestTemplate getRestTemplate();
}

The question is what i supposed to put as a param to get in body simply:

login=myName&password=myPassword&key=othereKey

without escaping, brackets or quota.

I've try to pass a string and i just get: "login=myName&password=myPassword&key=othereKey" but it is wrong because of quota signs.

like image 876
Vicek Avatar asked Oct 30 '13 11:10

Vicek


1 Answers

If I understand correctly, you want to post login and password parameters from a form to your method.

For this, you should ensure you have the following steps:

  1. Create a login form which has input text fields with login and password as names.
  2. Make sure the form has a POST method, you don't really want to have user's credentials in the URL as get params, but if you use case needs you to do it, you can.
  3. In your Interface, instead of using GsonHttpMessageConverter you should be using FormHttpMessageConverter. This converter accepts and returns content with application/x-www-form-urlencoded which is the correct content-type for form submissions.
  4. Your Param class should have fields which have the same name as the input text fields. In your case, login and password. After you do this, request parameters posted in the form will be available in the param instance.

Hope this helps.

like image 192
Akshay Avatar answered Oct 09 '22 05:10

Akshay