We use Unirest 1.5.4 for java. Our server responses on DELETE calls with a 204 - NO_CONTENT status and an empty response body. When I do synchronous delete call the following calls will end in an SocketTimeoutException.
For deeper investigation I swapped some lines in the server to respond status 200 and a "{}" body. Only with this server-side hack Unirest works fine.
here is my (failing) Unirest client code:
public static void main(String... args) throws UnirestException {
String baseUrl = "http://localhost:9010/orga/";
String orgaJson = "{}";
HttpResponse<String> postResponse = Unirest.post(baseUrl).body(orgaJson).asString();
System.out.println("POST status = " + postResponse.getStatus());
JSONObject orga = new JSONObject(postResponse.getBody());
String orgaId = orga.getJSONObject("_id").getString("$oid");
HttpResponse<String> deleteResponse = Unirest.delete(baseUrl+"{id}").routeParam("id", orgaId).asString();
System.out.println("DELETE status = " + deleteResponse.getStatus());
System.out.println("DELETE body = " + deleteResponse.getBody());
// the next call will cause a SocketTimeoutException
Unirest.post(baseUrl).body(orgaJson).asString();
}
I managed to solve a similar problem by setting timeouts slightly higher than the defaults. It looks like if you try to make multiple connections to a service like MailChimp every subsequent request takes a little more time. Try experimenting with it a bit.
Unirest.setTimeouts(10000, 30000);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.