public static void main(String[] args) throws Exception{
String urlString="
http://localhost:8080/NewB/callcenter?ac=crmuser
";URL url = new URL(urlString);
HttpURLConnection url_con= (HttpURLConnection)url.openConnection();
url_con.setDoOutput(true);
url_con.setRequestMethod("GET");
url_con.getOutputStream().flush();
url_con.getOutputStream().close();
InputStream in =url_con.getInputStream();
StringBuilder temp = new StringBuilder();
BufferedReader rd = new BufferedReader(new InputStreamReader(in));
// rd.reset();
while(rd.read()!=-1){
temp.append(rd.readLine());
}
System.out.println(new String (temp));
}
//服务器代码。
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
@SuppressWarnings("unchecked")
Map<String, String> params = request.getParameterMap();
if (params.containsKey("ac")){
PrintWriter write=response.getWriter();
write.println("1-china");
}
}
//当发送请求后,打印的结果是:
-china
这是什么原因?