java - "SocketException: Unexpected end of file from server" from servlet but not from standalone application -
i call servlet servlet. can call remote servlet standalone application cannot call servlet (it on glassfish). use same code call (i error @ last code line):
url serveraddress = new url(endpoint); //set initial connection httpurlconnection connection = (httpurlconnection) serveraddress.openconnection(); connection.setrequestmethod("post"); connection.setdooutput(true); connection.setdoinput(true); connection.setreadtimeout(timeout); connection.setrequestproperty("content-type", "text/xml; charset=iso-8859-1"); connection.connect(); outputstreamwriter wr = new outputstreamwriter(connection.getoutputstream()); wr.write(requestbody); wr.flush(); bufferedreader rd = new bufferedreader(new inputstreamreader(connection.getinputstream()));
it suspicious code can't read response of remote servlet servlet doesn't reply @ all. why reply when call standlone app? don't understand... got exception:
java.net.socketexception: unexpected end of file server @ sun.net.www.http.httpclient.parsehttpheader(httpclient.java:769) @ sun.net.www.http.httpclient.parsehttp(httpclient.java:632) @ sun.net.www.http.httpclient.parsehttpheader(httpclient.java:766) @ sun.net.www.http.httpclient.parsehttp(httpclient.java:632) @ sun.net.www.protocol.http.httpurlconnection.getinputstream(httpurlconnection.java:1049)
has idea? possible there restricitions servlets not use httpurlconnection? thanks!
this might happening because content-length
header not set. , because end of post request body not sent. server ending waiting till timeout end of stream.
you should try out these 2 things working:
- set content length header request body size before doing
connect()
- try closing
connection.getoutputstream().close()
send end of post request.
Comments
Post a Comment