我在Java后端代码中有一个从服务调用获得的字符串值。当我得到一个字符串的值时,我想发出一个发布请求,并将该字符串作为url编码的base 64字符串传递给端点。
问题是我收到套接字异常:连接重置错误。我正在使用HttpClient 4.5.2和IBM Websphere(Rational Application Development),更详细的错误是:
DefaultHttpClient org.apache.http.impl.client.DefaultRequestDirector tryConnect I/O Exception (java.net.SocketException) caught when connecting to {s} -> https://foo.bar:443: Connection reset
Java代码:
public ActionForward executeShowFormView(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
var stringResponse = serviceCall.getStringResponse();
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(serviceCall.getEndpointUrl());
StringEntity entity = new StringEntity("response=" + stringResponse, ContentType.APPLICATION_TYPE_URLENCODED);
post.setEntity(entity);
HttpResponse response1 = client.execute(post);
}
该如何解决该错误?
答案 0 :(得分:0)
在我的情况下,我使用了httpclient post方法。我将请求标头值设置为
post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1").
我的应用程序已投入生产并成功运行了1年。突然它停止工作,我收到了javax.net.ssl.SSLProtocolException:连接重置
修复:
我更改了post.setRequestHeader("Content-Type", "application/xml")
这解决了我的问题。