Reputation: 61
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.
Upvotes: 6
Views: 9574
Reputation: 141
You can have multiple converters because based on the object passed in, it will choose a converter for you. That said if you pass in a MultiValueMap it will for some reason add it to the headers because Android Annotations creates a HttpEntity. If you extend MultiValueMap as Ricardo suggested it will work.
Upvotes: 0
Reputation: 11
Example extending LinkedMultiValueMap:
@Rest(converters = {FormHttpMessageConverter.class, MappingJacksonHttpMessageConverter.class})
public interface RestClient extends RestClientRootUrl {
@Post("/login")
LoginResponse login(LoginRequest loginRequest);
}
public class LoginRequest extends LinkedMultiValueMap<String, String> {
public LoginRequest(String username, String password) {
add("username", username);
add("password", password);
}
}
Upvotes: 1
Reputation: 3198
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:
login
and password
as names.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.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.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.
Upvotes: 1