java.lang.IllegalStateException:已经在Java中的POST请求中连接

时间:2016-05-02 07:27:15

标签: java post

这就是我在做什么。在setdoOutput(true)之后,抛出异常。无法理解原因。

        URL url = new URL(subscriberUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        conn.setDoOutput(true);
        //After above line exception is thrown
        conn.setRequestProperty("Accept-Charset", charset);
        conn.setRequestProperty("Content-type", "application/json");

        OutputStream os = conn.getOutputStream();
        os.write(bytedata, 0, bytedata.length);
        os.flush();

        if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
            throw new RuntimeException("Failed : HTTP error code : "
                    + conn.getResponseCode());
        }
        conn.disconnect();

0 个答案:

没有答案