标签:.com zed case when and pre rom dia out ret
https://stackoverflow.com/questions/17991347/java-eofexception-when-getinputstream-from-post/18151239#18151239
If you use
conn.getInputStream()
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 in
conn.getErrorStream()
Thus, you have to check the HTTP response code before you decide which stream to read from:
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);
}
这样就能看到错误信息啦。
或者在服务器端看WCF的报错来看错误信息。
<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>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
setDoInput和setDoOutput的含义
andriod 连接wcf ,HttpURLConnection FileNotFoundException
标签:.com zed case when and pre rom dia out ret
原文地址:http://www.cnblogs.com/liangouyang/p/7237055.html