改造响应不包含响应数据

时间:2018-04-19 08:46:39

标签: android retrofit retrofit2

我正在使用此API https://westus.dev.cognitive.microsoft.com/docs/services/563309b6778daf02acc0a508/operations/563309b7778daf06340c9652/console 下面是我的改装代码。我无法在改造中发送原始JSON。

 public void createProfileAPI()
 {
     ApiInterface apiService = ApiClient.getClientRequest().create(ApiInterface.class);
     try
     {
        //pbVrd.setVisibility(View.VISIBLE);
         JSONObject paramObject = new JSONObject();
         paramObject.put("locale", "en-us");

         LocaleModel localeModel = new LocaleModel();
         localeModel.setLocale("en-us");
         Call<BaseModel> call = apiService.SearchResponse(localeModel);

         call.enqueue(new Callback<BaseModel>()
         {
            @Override
            public void onResponse(Call<BaseModel> call, Response<BaseModel> response)
            {
                int responseCode = response.code();
                Log.d("Deepakw" , responseCode+"");

                BaseModel response1 = response.body();
                Log.d("Deepak" , response.body().getIdentificationProfileId() + " //// " +response1.getIdentificationProfileId()+""); 
            }

            @Override
            public void onFailure(Call<BaseModel> call, Throwable t)
            {
                Log.d("Responce Failed ", "failed Response Mersen Fuse ");
                String message = t.getMessage();
                Log.d("failure", message);
            }
        });
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

public class ApiClient {

    public static final String BASE_URL = "https://westus.api.cognitive.microsoft.com/spid/v1.0/";
    private static Retrofit retrofit = null;

    public static Retrofit getClientRequest() {
        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }    
}

public interface ApiInterface {    
    @Headers({
            "Content-Type: application/json",
            "Ocp-Apim-Subscription-Key:  0219cf3e3d444f0584f80b3a84613d12"
    })
    @POST("verificationProfiles")
    Call<BaseModel> SearchResponse(@Body LocaleModel body);
};

我无法得到答复 API客户端 请帮忙

2 个答案:

答案 0 :(得分:0)

         //In ApiInterface do like this
      @Headers("charset:UTF-8")
            @POST("verificationProfiles")
            Call<BaseModel> SearchResponse(
                    @Header("Content-Type") String contentType,
                    @Body LocaleModel body);

have you tried @SerializedName("") and @Expose in your pojo class 

   @SerializedName("status")
    @Expose
    private Boolean status;

答案 1 :(得分:0)

您可以使用Map代替JSONObject 例如:

Headers("Content-Type: application/json")
@POST("/apipath")
request(@Body Map<String, String> body);