导入依赖包:commons-codec-1.10.jar ,commons-httpclient-3.1.0.jar,commons-logging-1.2.jar
HttpClient client = new HttpClient();
// 设置代理服务器地址和端口// client.getHostConfiguration().setProxy( "192.168.10.200", 80 );
// 使用 GET 方法 ,如果服务器需要通过 HTTPS 连接,那只需要将下面 URL 中的 http 换成 https
HttpMethod method = new GetMethod("http://192.168.10.200/Module/Message/YXFCInterface.ashx?FWDM="+hsname);
// 这里设置字符编码,避免乱码
method.setRequestHeader("Content-Type", "text/html;charset=utf-8");
client.executeMethod(method);
// 打印服务器返回的状态
System.out.println(method.getStatusLine());
// 获取返回的html页面
byte[] body = method.getResponseBody();
// 打印返回的信息
String json = new String(body, "utf-8");
System.out.println(json);
// 释放连接
method.releaseConnection();