05-09 08:59:33.258 14174-14247/com.example.ga.retrofitposttest D/OkHttp: --> POST http://DOMAINHIDDEN.com/solicitation/create?X-Authorization=dda15b84304fe58cbcc4f6570363 http/1.1
05-09 08:59:33.258 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Content-Type: application/json; charset=UTF-8
05-09 08:59:33.258 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Content-Length: 183
05-09 08:59:33.259 14174-14247/com.example.ga.retrofitposttest D/OkHttp: {"description":"descript22222222ion goes here","file":"file goes here","geolat":"31","geolong":"32","location":"list","protocol":"203120312","type":"2xx","userid":"use2rid goes here"}
05-09 08:59:33.259 14174-14247/com.example.ga.retrofitposttest D/OkHttp: --> END POST (183-byte body)
05-09 08:59:33.267 14174-14248/com.example.ga.retrofitposttest D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
05-09 08:59:33.319 14174-14248/com.example.ga.retrofitposttest I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 10/21/15, 369a2ea, I96aee987eb
05-09 08:59:33.322 14174-14248/com.example.ga.retrofitposttest I/OpenGLRenderer: Initialized EGL, version 1.4
05-09 08:59:33.416 14174-14174/com.example.ga.retrofitposttest W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
05-09 08:59:33.646 14174-14247/com.example.ga.retrofitposttest D/OkHttp: <-- 200 OK http://DOMAINHIDDEN.com/solicitation/create?X-Authorization=dda15b84304fe58cbcc4f6570363 (386ms)
05-09 08:59:33.646 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Date: Tue, 09 May 2017 11:59:34 GMT
05-09 08:59:33.646 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Server: Apache/2.4.18 (Ubuntu)
05-09 08:59:33.646 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Access-Control-Allow-Origin: *
05-09 08:59:33.646 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Access-Control-Allow-Methods: GET, POST, OPTIONS
05-09 08:59:33.646 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With
05-09 08:59:33.646 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Access-Control-Allow-Credentials: true
05-09 08:59:33.646 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Cache-Control: no-cache
05-09 08:59:33.647 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Set-Cookie: XSRF-TOKEN=eyJpdiI6ImM3XC9KSE8yMVh0ZGpZWEt0UUNFTmd3PT0iLCJ2YWx1ZSI6IitQSjZhallLekdaKzNLTDFZZFQ1ZFBXOG5IbUNCM1duUFpMS3ZvV0hUdVJQeUdqTzdlQTNJakk3ODlGOVo4YzNRWXJrT2tZVEMxT3VkcnhuMHZVY013PT0iLCJtYWMiOiI3YTlhMDlmNTMwY2ZjYzk0YjFhN2UzNWE5OGVjYzEwYWQ2YjllMGQyZjUxODM0Y2VkZjU4NmI3YjUyNDM0OTEwIn0%3D; expires=Tue, 09-May-2017 13:59:34 GMT; Max-Age=7200; path=/
05-09 08:59:33.647 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Set-Cookie: laravel_session=eyJpdiI6InJXM0s5c1NDbnF2M1BlZXNTa0pqalE9PSIsInZhbHVlIjoiV3Eyc1hST3kxRzdoTEVFajBzdSs4emZcL0ZvXC9TMVNBUUZucnB2VDNcL3ozZkc1cjBvR042RmlhZDRMSGtIcDZtWk44V1o0T3V4TE1uREFQdlVyWFJHZVE9PSIsIm1hYyI6IjRiMWNhYzQ2MTg5MGViN2RiN2I3YTVlMWQxN2M5YzNjODQ0ODJmYmIwNjg5NzM3ZGUwNGM3NDhmZDEyMTk5YjQifQ%3D%3D; expires=Tue, 09-May-2017 13:59:34 GMT; Max-Age=7200; path=/; HttpOnly
05-09 08:59:33.647 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Content-Length: 0
05-09 08:59:33.647 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Keep-Alive: timeout=5, max=100
05-09 08:59:33.647 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Connection: Keep-Alive
05-09 08:59:33.647 14174-14247/com.example.ga.retrofitposttest D/OkHttp: Content-Type: text/html; charset=UTF-8
05-09 08:59:33.647 14174-14247/com.example.ga.retrofitposttest D/OkHttp: <-- END HTTP (0-byte body)
如您所见,我得到OkHttp: <-- 200 OK
。
如果我得到200 OK,为什么通过onFaiure
回复回调回复。
Solicitation solicitation = new Solicitation("2xx", "list", "31", "32", "descript22222222ion goes here", "file goes here", "use2rid goes here", "203120312");
ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
Call<Solicitation> call = apiService.createSolicitation(API_KEY, solicitation);
call.enqueue(new Callback<Solicitation>() {
@Override
public void onResponse(Call<Solicitation> call, Response<Solicitation> response) {
Log.d("Response::", "Success!");
}
@Override
public void onFailure(Call<Solicitation> call, Throwable t) {
Log.e("Response::", "Fail!!");
}
});
上面的代码放在了创建方法上,仅用于测试。 ApiInterface有两个方法,一个用于检索,一个用于创建,我正在使用上面的create方法。它有效,但它仍然会失败。
日志的最后一行如下:
05-09 08:59:33.663 14174-14174/com.example.ga.retrofitposttest E/Response::: Fail!!
这正是我在onFailure
编码的内容。
答案 0 :(得分:1)
可能是Retrofit命中onFailure,即使调用返回200也无法解析响应,因为它是零长度和text / html - 你期待JSON回来吗?检查Throwable t以检查Retrofit抛出的异常。