我只能從文檔中運行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