Java HTTP响应代码,URL,IOException [英] Java HTTP Response Code, URL, IOException
本文介绍了Java HTTP响应代码,URL,IOException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从我正在尝试与之通信的服务器获得503响应。现在,它在日志中向我显示了这一点,但是,我想要捕获它触发并处理它的IOException,当且仅当响应代码是503时,没有别的。我该怎么做?
I'm getting a 503 response from a server that I'm trying to communicate with. Now, it shows me this in the log, but, I want to catch the IOException that it fires and deal with it if and only if the response code is 503, and nothing else. How would I do this?
编辑:
这是我的代码的一部分:
Here's part of my code:
inURL = new BufferedReader(new InputStreamReader(myURL.openStream()));
String str;
while ((str = inURL.readLine()) != null) {
writeTo.write(str + "\n");
}
inURL.close();
推荐答案
如果使用 java.net .HttpURLConnection
,使用方法 getResponseCode()
如果使用 org.apache.commons.httpclient.HttpClient
, executeMethod(...)
返回响应代码
If using org.apache.commons.httpclient.HttpClient
, executeMethod(...)
returns the response code
这篇关于Java HTTP响应代码,URL,IOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文