如何获得响应状态

时间:2016-04-13 13:42:00

标签: java http-headers

祝你好运!

示例代码:

        try {
            URL object = new URL(url);
            HttpURLConnection con = (HttpURLConnection) object.openConnection();
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setRequestProperty("Content-Type", "application/json; charset=utf-8");
            con.setRequestProperty("Accept", "application/json; charset=utf-8");
            con.setRequestMethod("POST");
            OutputStreamWriter wr= new OutputStreamWriter(con.getOutputStream());
            wr.write(json);
            wr.flush();
            InputStream inputStream = con.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String line = "";
            while ((line=reader.readLine()) != null) {
                response += "\n" + line;
            }

如何获取回复状态? 请帮助!

1 个答案:

答案 0 :(得分:0)

con.getResponseCode();`//获取状态