我只能从文档中运行hello world示例(GithubService)。如何使用翻新2进行POST请求?
问题是,当我运行我的代码,我得到以下错误,里面的onFailure()
畸形的JSON使用JsonReader.setLenient(真)接受第1行 列1路$
我的API需要POST params值,所以不需要将它们编码为JSON,但它确实会在JSON中返回响应。
对于响应,我得到了使用工具生成的ApiResponse类。
我的界面:
public interface ApiService {
@POST("/")
Call<ApiResponse> request(@Body HashMap<String, String> parameters);
}
这里是我使用的服务:
HashMap<String, String> parameters = new HashMap<>();
parameters.put("api_key", "xxxxxxxxx");
parameters.put("app_id", "xxxxxxxxxxx");
Call<ApiResponse> call = client.request(parameters);
call.enqueue(new Callback<ApiResponse>() {
@Override
public void onResponse(Response<ApiResponse> response) {
Log.d(LOG_TAG, "message = " + response.message());
if(response.isSuccess()){
Log.d(LOG_TAG, "-----isSuccess----");
}else{
Log.d(LOG_TAG, "-----isFalse-----");
}
}
@Override
public void onFailure(Throwable t) {
Log.d(LOG_TAG, "----onFailure------");
Log.e(LOG_TAG, t.getMessage());
Log.d(LOG_TAG, "----onFailure------");
}
});
发布完整的堆栈跟踪,但问题是有可能的是,响应的格式不正确。在改造中有很多调试选项,使用它们 – njzk2