这一阵子在搞文件上传。
遇到了这样一个问题:
在Java中写一段使用HttpURLConnection POST一段数据到服务器,可是 服务器端却读不到数据,
得到的InputStream的 avilable 一直是0
发送端代码如下:
URL u = new URL("http://127.0.0.1:8080/supload/x.jsp");
HttpURLConnection hu = (HttpURLConnection) u.openConnection();
hu.setRequestMethod("POST");
hu.setRequestProperty("content-type", "text/html");
hu.setRequestProperty("enctype", "multipart/form-data");
hu.setDoOutput(true);
hu.setDoInput(true);
hu.setUseCaches(false);
hu.setInstanceFollowRedirects(true);
hu.connect();
OutputStream os = hu.getOutputStream();
InputStream is = hu.getInputStream();
os.write("abc".getBytes());
os.flush();
os.close();
BufferedReader br = new BufferedReader(new I