做简单的两个服务器间的请求发送和返回,注释一行System.out.print语句后,结果截然不同,非常奇怪://post方式发送一个带参数表单给t2.jsp
String query = "cmd=getAllCustomer";
URL u = new URL("http://localhost:8080/test/t2.jsp");
HttpURLConnection uc =(HttpURLConnection) u.openConnection();
uc.setDoOutput(true);
uc.setRequestMethod("POST");
uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");PrintWriter pw = new PrintWriter(uc.getOutputStream());
pw.println(query);
pw.close();
//获取返回值
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));System.out.println("t0:"+in.readLine());//注意这一句!
String res = in.readLine();
in.close();
System.out.println("t1:"+res);执行时,输出结果为:
t0:
t1:cmd=getAllCustomer  注:这是t2.jsp返回的内容
但如果注释掉“System.out.println("t0:"+in.readLine());”,则输出结果为:
t1:
即取不到t2.jsp返回的内容。
请教这是为什么?