代码
HttpURLConnection hc=(HttpURLConnection) (new URL(localhost)).openConnection();
hc.setRequestMethod("POST");
hc.setRequestProperty("Content-Length", data.length()+"");
hc.setDoOutput(true);
OutputStream os=hc.getOutputStream();
os.write(data.getBytes());
已知 最后一行报错
data里面有中文就会报错
错误信息:
java.net.ProtocolException: exceeded content-length limit of 47 bytes
------解决思路----------------------
hc.setRequestProperty("Content-Length", data.length()+""); 把这个去掉,或者把长度值乘以10.