我尝试使用Retrofit库在Android上使用API时失败,但在使用POSTMAN时我可以看到预期的结果.
邮递员设定
api url(基地+控制器)
HTTP方法设置为POST
点击了from-data或x-www-form-urlencoded
然后我在键/值字段上传递两个参数.
ANDROID改装设置
@POST("/GetDetailWithMonthWithCode")
void getLandingPageReport(@Query("code") String code,
@Query("monthact") String monthact,
Callback<LandingPageReport> cb);
@FormUrlEncoded
@POST("/GetDetailWithMonthWithCode")
void getLandingPageReport(@Field("code") String code,
@Field("monthact") String monthact,
Callback<LandingPageReport> cb);
Run Code Online (Sandbox Code Playgroud)
这些选项都不起作用.但结果是{}.
UPDATE
使用标准HttpClient(和HttpPost)类的相同设置工作正常.
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("code", "testcode"));
urlParameters.add(new BasicNameValuePair("monthact", "feb-2015"));
post.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = client.execute(post);
Run Code Online (Sandbox Code Playgroud)
为什么我不能做这个请求并在Retrofit中获得正确的响应?
更新2
@POST("/GetDetailWithMonthWithCode")
void getLandingPageReport(@Query("code") String code,
@Query("monthact") String monthact,
Callback<List<LandingPageReport>> cb);
@FormUrlEncoded
@POST("/GetDetailWithMonthWithCode")
void getLandingPageReport(@Field("code") String …Run Code Online (Sandbox Code Playgroud)