繁体   English   中英

HttpUrlConnection getOutputStream()抛出java.net.SocketException:服务器上的文件意外结束

[英]HttpUrlConnection getOutputStream() throwing java.net.SocketException: Unexpected end of file from server

我正在尝试使用Java代码调用REST Web服务。

我可以通过Rest Client Postman来执行它。

我的代码:

    URL url = new URL(appURL);
    httpCon = (HttpURLConnection) url.openConnection();
    httpCon.setRequestMethod("POST");
    httpCon.setDoInput(true);
    httpCon.setUseCaches(false);
    httpCon.setAllowUserInteraction(false);
    httpCon.setDoOutput(true);
    httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    httpCon.setRequestProperty("Host", "www.astecanalytics.com");
    httpCon.setRequestProperty("Expect", "100-continue");

    OutputStream outstream = httpCon.getOutputStream();

我得到以下错误:

java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:772)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
    at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:1789)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1091)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
    at com.ktt.business.keywords.webservice.ExecuteWebServiceKeyword.postHTTPRequestAndGetRespone(ExecuteWebServiceKeyword.java:618)

有人可以帮忙吗?

由于服务器的响应正常,因此服务器端没有问题。 将通过Rest Client发送的请求正文与从代码发送的请求正文进行比较。 然后尝试映射。

检查此教程链接: http : //www.mkyong.com/java/how-to-send-http-request-getpost-in-java/

当我尝试执行与您目前正在尝试的相同操作时,这对我有所帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM