我知道HTTP头是什么以及HTTP数据格式如何,我也知道如何从Java发布HTTP帖子,
喜欢
StringBuffer result = new StringBuffer();
PrintWriter out = null;
BufferedReader in = null;
StringBuffer result = new StringBuffer();
try {
URL realUrl = new URL("http://somesite/somepage.htm");
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
e.printStackTrace();
}
我可以使用像这样写入流到Web服务器的代码,并且也可以读取流。
这是我的问题。
HTTP POST方法到底是做什么的,我的意思是客户端如何与Web服务器通信?
如果Web服务器只读取HTTP POST标头而不从客户端读取流,会发生什么? 流会卡在某个地方吗?
谢谢。