我已经实现了我的Android代码第一次改造和面向follwing问题如何发送的JSONObject到改造API调用的Android
收到以下错误:java.lang.IllegalArgumentException异常:@Body参数不能与形式使用或多部分编码。 (参数#1)
我已经实现了我的代码像下面
public interface APIService {
@FormUrlEncoded
@POST("/")
@Headers({
"domecode: axys",
"Content-Type: application/json;charset=UTF-8"
})
Call<JsonObject> sendLocation(@Body JsonObject jsonObject);
}
public class ApiUtils {
static String tempUrl = "http://192.168.16.114:8092/api/v1/location/tsa/";
public static APIService getAPIService() {
return RetrofitClient.getClient(tempUrl).create(APIService.class);
}
}
public class RetrofitClient{
private static Retrofit retrofit = null;
public static Retrofit getClient(String baseUrl){
if(retrofit==null){
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
传递价值,以API调用
JsonObject postParam = new JsonObject();
try {
postParam.addProperty(Fields.ID, "asdf");
}
Call<JsonObject> call = apiService.sendLocation(postParam);
call.enqueue(new Callback<JsonObject>() {
@Override
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
Log.d("response","Getting response from server : "+response);
}
@Override
public void onFailure(Call<JsonObject> call, Throwable t) {
Log.d("response","Getting response from server : "+t);
}
}
);
不要给回调'apiService.sendLocation(jsonObject.enqueue (new callback(){...});'。 –