I'm using the unirest http wrapper (http://unirest.io/java.html) in a Java application to send http post requests. Unfortunately I keep getting a "broken pipe" error:
com.mashape.unirest.http.exceptions.UnirestException: java.net.SocketException: Broken pipe
com.mashape.unirest.http.exceptions.UnirestException: java.net.SocketException: Broken pipe
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:145)
at com.mashape.unirest.request.BaseRequest.asString(BaseRequest.java:56)
The code I'm using to call it is as follows:
public static int doHTTPPostWithAdditionalHeaders(String data, String url, HashMap<String, String> additionalHeaders) {
try {
Unirest.setTimeouts(10000, 10000);
HttpResponse<String> jsonResponse = Unirest.post(url)
.headers(additionalHeaders)
.body(data)
.asString();
return jsonResponse.getStatus();
} catch (Exception e) {
System.out.println("doHTTPPostWithAdditionalHeaders failed: "+e.toString());
}
return 0;
}
It works most of the time but seems to fail when I'm hammering it with lots of requests. Have any of you got any ideas how I might solve this, or perhaps could you recommend a more robust solution? This post operation is mission critical to my application.
Looks like it was a simple case of the data I was posting being too large for the allocated timeouts.
Old
New