【发布时间】:2017-01-21 19:19:32
【问题描述】:
无法使用Retrofit 2.0 发送POST api 数据中的原始JSON 数据
try {
JSONObject myUserData = new JSONObject();
myUserData.put("mobile", "917023847899");
myUserData.put("displayName", "Deepuu");
myUserData.put("info", "AD");
myUserData.put("photo", "");
myUserData.put("displayName", "Deepu");
JSONObject deviceData = new JSONObject();
;
deviceData.put("deviceId", "2124578910556991");
deviceData.put("pnToken", "klklklkl");
deviceData.put("os", "android");
deviceData.put("targetTopic", "jkjkjkjkj");
myUserData.put("device", "" + deviceData);
OkHttpClient client = new OkHttpClient();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
Api Ainterface = retrofit.create(Api.class);
Call<Response> data = Ainterface.getResponse(myUserData);
data.enqueue(new Callback<Response>() {
@Override
public void onResponse(Call<Response> call, retrofit2.Response<Response> response) {
if (response.isSuccessful()) {
Response rr = response.body();
Integer ss = rr.getStatusCode();
Log.e("I Am", "Success" );
}
}
@Override
public void onFailure(Call<Response> call, Throwable t) {
Log.e("I Am", "Failed");
}
});
我的界面:
@POST("appUsers/")
Call<Response> getResponse(@Body RequestBody value);
谁能建议使用Retrofit 2.0 在POST api 中发送原始JSON 数据的解决方案?我是使用 Retrofit 的新手;请帮忙,因为我在 onResponse 方法中得到了 null 响应。
【问题讨论】:
-
添加你的 Api 和改造服务生成器类代码
-
问题是我无法将这些 JSON 对象作为参数发送并得到空响应.. :(
标签: android api android-studio retrofit retrofit2