Android Retrofit Causes Socket Timeout Exception

时光毁灭记忆、已成空白 提交于 2019-12-12 15:53:14

问题


I am making a POST call to a tomcat server running Struts2 using the retrofit library on an Android Galaxy S3 (/Nexus 7) device. The POST call fails. The tomcat log shows Socket timeout exception.

The same POST using the exact same headers done via curl does not have any issues. I verified that the data on the wire matches using charles proxy.

Any tips/ideas on debugging this issue.

The post call is as follows

@POST(Constants.URL_GET_ORDER_LIST_BASE)
   void getCardOrderList(@Body GetOrderListRequest getOrderListRequest, Callback<GetOrderListResponse> cbGetOrderListResponse);

Please let me know if I need to add more information to explain this better.


回答1:


Adding Square's OKHTTP library into the libs folder fixed the issue.




回答2:


I was having SocketTimeoutExceptions too. Pay attention to always add the final slash to your POST call.

Example:

BAD

@POST("/customers")

GOOD

@POST("/customers/")

My mistake was just this :)



来源:https://stackoverflow.com/questions/17439935/android-retrofit-causes-socket-timeout-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!