这个简单的post方法没有向服务器(servlet)发送任何内容。我可以,但我不能发帖!
@Override
protected String doInBackground(String... params) {
try {
URL url = new URL("http://ipaddr:8080/work/wh");
HttpURLConnection client = (HttpURLConnection) url.openConnection();
client.setRequestMethod("POST");
client.setDoOutput(true);
client.setChunkedStreamingMode(0);
client.connect();
OutputStream outputStream = client.getOutputStream();
PrintWriter pw = new PrintWriter(outputStream);
pw.println(System.currentTimeMillis());
pw.println(System.currentTimeMillis());
pw.println(new Float(5.6));
pw.println(new Integer(3));
pw.println(new Integer(2));
pw.println(new Integer(32));
pw.println(new Integer(2));
pw.close();
outputStream.close();
}catch(Exception e){
Log.e("text", "ux " + e.getMessage());
}
return null;
}
在服务器端如果我试图读取任何行new Scanner(request.getInputStream()).nextLine();
我得到
NoSuchElementException:找不到行
您认为可能是什么问题?
答案 0 :(得分:-1)
在关闭之前尝试刷新PrintWritter / Outputstream。