【发布时间】:2018-07-26 10:46:19
【问题描述】:
邮递员描述:
界面:
public interface PostService {
@Headers("Content-Type: application/json")
@FormUrlEncoded
@POST("/user/login")
Call<User> login(@Body User user);
}
调用函数:
User user = new User("student", "student@gmail.com");
Call<User> noticeList = RetrofitAPI.getService().login(user);
noticeList.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
Log.i("postdata", "v =" + response.body().getId());
}
@Override
public void onFailure(Call<User> call, Throwable throwable) {
Toast.makeText(ActivityLogin.this, "Server taking time try refreshing", Toast.LENGTH_SHORT).show();
}
});
我们如何将json post数据发送到服务器?
【问题讨论】: