I'm new to Retrofit. How can I send param and get Json from bellow url ?
http://xxx:8087/courier.svc/login?username=jim&password=123456
I need to a link for tutorial .
This code is in my MainActivity
:
private void loadJSON(String username, String password) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://192.168.8.11:8087/sample.svc/")
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestInterface_Login request = retrofit.create(RequestInterface_Login.class);
Call<JSONResponseLogin> call = request.getJSON(username, password);
call.enqueue(new Callback<JSONResponseLogin>() {
@Override
public void onResponse(Call<JSONResponseLogin> call, Response<JSONResponseLogin> response) {
JSONResponseLogin jsonResponse = response.body();
data = new ArrayList<>(Arrays.asList(jsonResponse.getLogin()));
}
@Override
public void onFailure(Call<JSONResponseLogin> call, Throwable t) {
Log.d("Error", t.getMessage());
}
});
}
My ModelLogin
:
public class ModelLogin {
private String username;
private String password;
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
}
My RequestInterface_Login
:
public interface RequestInterface_Login {
@GET("/login/{username}/{password}")
Call<JSONResponseLogin> getJSON(@Path("username") String username, @Path("password") String password);
}
My JSONResponseLogin
:
public class JSONResponseLogin {
private ModelLogin[] login;
public ModelLogin[] getLogin() {
return login;
}
}
But get me NullPointerException
!
I get json
from service same bellow :
{"Key":null,"Response":1}