如何通过改造将Map<字符串,字符串>参数或对象传递到POST请求?
我在将地图参数或对象传递到改造POST请求时遇到问题。
我遵循方形,kdubb实验室教程和这个线程,我无法弄清楚。
我当前有效的代码:
public interface FacebookUser {
@FormUrlEncoded
@POST("/user/login-facebook")
void login(
@Field("fb_access_token") String fbAccessToken,
@Field("os") String os,
@Field("device") String device,
@Field("os_version") String osVersion,
@Field("app_version") String appVersion,
@Field("online") String online,
Callback<FacebookLoginUserResponse> callback
);
}
和代码:
RestAdapter restAdapter = new RestAdapter.Builder()
.setServer(requestMaker.getUrl())
.build();
FacebookUser facebookUser = restAdapter.create(FacebookUser.class);
facebookUser.login(getFbAccessToken(),
getString(R.string.config_os),
Info.getAndroidId(getBaseContext()),
Build.VERSION.RELEASE,
Info.getAppVersionName(getBaseContext()),
"" + 1,
new Callback<FacebookLoginUserResponse>() {
@Override
public void success(FacebookLoginUserResponse facebookLoginUserResponse, Response response) {
}
@Override
public void failure(RetrofitError retrofitError) {
}
});
当我尝试使用此接口时,我从服务器收到缺少参数:
public interface FacebookUser {
@POST("/user/login-facebook")
void login(
@Body Map<String, String> map,
Callback<FacebookLoginUserResponse> callback
);
}
和地图:
HashMap<String, String> map = new HashMap<String, String>();
map.put("fb_access_token", getFbAccessToken());
map.put("os", "android");
map.put("device", Info.getAndroidId(getBaseContext()));
map.put("os_version", Build.VERSION.RELEASE);
map.put("app_version", Info.getAppVersionName(getBaseContext()));
map.put("online", "" + 1);
问题:这是怎么回事?如何将对象传递给请求?