我们使用 Unirest 1.5.4 for java。我们的服务器以 204 - NO_CONTENT 状态和空响应正文响应 DELETE 调用。当我进行同步删除调用时,以下调用将以 SocketTimeoutException 结束。
为了进行更深入的调查,我在服务器中交换了一些行以响应状态 200 和“{}”正文。只有使用此服务器端 hack Unirest 才能正常工作。
这是我的(失败的)Unirest 客户端代码:
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();
}