String urlstr="servie="+URLEncoder.encode(serivce,"UTF-8") +"&partener="+URLEncoder.encode(partener,"UTF-8");
String newUrl="http://10.53.78.116:80/gateway.do?"+urlstr;
URL realUrl= new URL(newUrl);
URLConnection connect=realUrl.openConnection();
//设置请求超时
connection.setConnectionTimeOut(6000);
//设置通用的请求属性头
connection.setRequestProperty("accept","*/*");
connection.setRequestProperty("connection","Keep-Alive");
connection.setRequestProperty("user-agent","Mozilla/4.0(compatiable;MSIE 6.0; Windows NT 5.1; sv1)");
connection.connect();
//设置响应超时
connection.setReadTime(6000);
//获取所有响应头字段
Map<String,List<String>> map= connection.getHeaderFields();
for(String key :map.keySet()){
system,out.println(map.getKey(key));
}
if(conn.getResponseCode()==200){//证明发送成功
return true;
}
//定义bufferedReader字符流读取URL的响应
BufferedReader bred=new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line="";
while((line=bred.readLine()) !=null){
str+=line
}
syso....(str);
关闭 流
bred.close();