https://stackoverflow.com/questions/17991347/java-eofexception-when-getinputstream-from-post/18151239#18151239java
If you use服务器
conn.getInputStream()
app
everytime, it will throw a java.io.FileNotFoundException
in the case when your request is unsuccessful, basically for any HTTP response code of 400 or above. In this case, your response body lies inide
conn.getErrorStream()
post
Thus, you have to check the HTTP response code before you decide which stream to read from:ui
int status = conn.getResponseCode(); BufferedInputStream in; if (status >= 400 ) { in = new BufferedInputStream( conn.getErrorStream() ); } else { in = new BufferedInputStream( conn.getInputStream() ); }
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String str;
while ((str = reader.readLine()) != null) {
sb.append(str);
}
这样就能看到错误信息啦。this
或者在服务器端看WCF的报错来看错误信息。spa
<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>code
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------xml
setDoInput和setDoOutput的含义