3

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.

pixel
  • 24,905
  • 36
  • 149
  • 251
K K
  • 101
  • 1
  • 8

2 Answers2

2

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

K K
  • 101
  • 1
  • 8
  • I had the timeout issue every alternative POST calls using retrofit library. Adding OKHTTP jar file from fixed the issue. Thanks! – nous Mar 12 '14 at 03:23
  • BAD ANSWER! I'm having the same issue and I can't figure out how to proceed. Please detail the steps to include the library (jar file? gradle dependency?). please complete your answer. -1 – voghDev Jul 01 '15 at 09:56
1

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 :)

voghDev
  • 5,641
  • 2
  • 37
  • 41
  • I was getting timeout very often. After seeing your answer and adding the final slash, it seems that the problem is gone. Can you explain it any further? Why adding the final slash matters? – Ashkan Sarlak Sep 15 '15 at 06:40
  • see http://programmers.stackexchange.com/a/187006 The final slash is indicator of a list response (nothing's mandatory). I don't understand why it has effect on frequency of timeout errors. – Ashkan Sarlak Sep 15 '15 at 12:14
  • 1
    What about GET requests? – IgorGanapolsky Oct 22 '15 at 19:22