https://stackoverflow.com/questions/17991347/java-eofexception-when-getinputstream-from-post/18151239#18151239
If You use
conn.getInputStream()
Everytime, it would throw a in the case when java.io.FileNotFoundException your request was unsuccessful, basically for any HTTP response code of 40 0 or above. Your response body lies in
conn.getErrorStream()
Thus, you had to check the HTTP response code before you decide which stream to read from:
IntStatus=Conn.Getresponsecode();BufferedinputstreamInch;If (Status>= 400 ) { in = new bufferedinputstream ( conn geterrorstream () ); } else {= new Bufferedinputstream ( Conn. Getinputstream ); /span>
BufferedReader reader = new BufferedReader (new InputStreamReader (in));
StringBuilder sb = new StringBuilder ();
String str;
while ((str = reader.readline ()) = null) {
Sb.append (str);
}
So you can see the error message.
Or, look at the error message on the server side of WCF errors.
<system.diagnostics>
<sources>
<source name= "System.ServiceModel" switchvalue= "Warning" propagateactivity= "true" >
<listeners>
<add name= "xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name= "xml" type= "System.Diagnostics.XmlWriterTraceListener" initializedata= "D:\wcf.svclog"/>
</sharedListeners>
</system.diagnostics>
--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------
The meaning of Setdoinput and setdooutput
- public void setdoinput ( boolean doinput) sets the value of this URLConnection doInput field to the specified value.
- url connections are available for input and/or output. If you intend to use the URL connection for input, set the DoInput flag to true, or set to false. The default value is true.
- public Void setdooutput (boolean dooutput) this URLConnection 's dooutput The value of the field is set to the specified value.
- url connections are available for input and/or output. If you intend to use the URL connection for output, set the DoOutput flag to true, or set to < if you do not intend to use it span class= "keyword" >false. The default value is false.
- Httpurlconnection.setdooutput (true); You can use Conn.getoutputstream () later. Write ()
- Httpurlconnection.setdoinput (true); You can use Conn.getinputstream later (). read ();
- The GET request does not use Conn.getoutputstream () because the parameter is appended directly to the address, so the default is false.
- Post requests (for example, file uploads) require a large amount of data to be transferred to the service area, which is placed inside the body of the HTTP, so you need to write the data to the server after the connection is established.
- Because Conn.getinputstream () is always used to get the response from the server, the default value is true.
Andriod connecting WCF, HttpURLConnection filenotfoundexception