0
我有以下代碼我必須從服務器獲取響應代碼嗎?
URL url = new URL(pushURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/restService");
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
if(conn.getResponseCode() == 200){
logger.debug("Success");
} else {
logger.debug("Time out set for 30 seconds");
}
String input = writer.getBuffer().toString();
OutputStream os = conn.getOutputStream();
如果我不感興趣,從服務器的響應,我可以去掉下面的代碼?
if(conn.getResponseCode() == 200){
logger.debug("Success");
} else {
logger.debug("Time out set for 30 seconds");
}
考慮到該代碼,在它的全部,因爲它是導致java.net.ProtocolException
,是有辦法還是搶服務器響應並執行conn.getOutputStream();
?按什麼順序?除了明顯的報告問題之外,沒有獲得迴應的後果是什麼?
謝謝你的回答和教程 – Mushy