这就是我在做什么。在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();