String content = MessageUtil.createContentMessage(head,data);
URL postUrl = null;
DataOutputStream output = null;
try {
postUrl = new URL("http://183.63.131.106:40011/extService/ghbExtService.do"); //URL请求地址
//postUrl = new URL("http://183.63.131.106:40013/extServiceTest/ghbExtService.do"); //URL请求地址
HttpURLConnection urlcon = (HttpURLConnection) postUrl.openConnection();
int contentLength = content.getBytes().length; //获取报文长度
urlcon.setConnectTimeout(1000*15);
urlcon.setReadTimeout(1000*60*2);
urlcon.setRequestMethod("POST"); //post请求方式
urlcon.setUseCaches(false); //post请求不能使用缓存
urlcon.setRequestProperty("Content-Length", String.valueOf(contentLength));
if("1".equals(content.charAt(5))){
urlcon.setRequestProperty("Content-Type", "application/xml; charset=UTF-8");
}
if("2".equals(content.charAt(5))){
urlcon.setRequestProperty("Content-Type", "www-form-urlencoded");
urlcon.setRequestProperty("charset", "UTF-8");
}
urlcon.setDoInput(true); //默认为true
urlcon.setDoOutput(true); //默认为true
//urlcon.connect(); //urlcon.getOutputStream()会隐含的进行connect();
output = new DataOutputStream(urlcon.getOutputStream());
output.writeBytes(content);
output.flush();
output.close();
String str=null;
//if("1".equals(String .valueOf(content.charAt(5)))){
BufferedReader buffer =new BufferedReader(new InputStreamReader(urlcon.getInputStream()));
StringBuffer strBuffer = new StringBuffer();
String str = null;
while((str=buffer.readLine())!=null){
strBuffer.append(str);
}
System.out.println("返回报文为: "+strBuffer);
buffer.close();
//}
urlcon.disconnect();
URL postUrl = null;
DataOutputStream output = null;
try {
postUrl = new URL("http://183.63.131.106:40011/extService/ghbExtService.do"); //URL请求地址
//postUrl = new URL("http://183.63.131.106:40013/extServiceTest/ghbExtService.do"); //URL请求地址
HttpURLConnection urlcon = (HttpURLConnection) postUrl.openConnection();
int contentLength = content.getBytes().length; //获取报文长度
urlcon.setConnectTimeout(1000*15);
urlcon.setReadTimeout(1000*60*2);
urlcon.setRequestMethod("POST"); //post请求方式
urlcon.setUseCaches(false); //post请求不能使用缓存
urlcon.setRequestProperty("Content-Length", String.valueOf(contentLength));
if("1".equals(content.charAt(5))){
urlcon.setRequestProperty("Content-Type", "application/xml; charset=UTF-8");
}
if("2".equals(content.charAt(5))){
urlcon.setRequestProperty("Content-Type", "www-form-urlencoded");
urlcon.setRequestProperty("charset", "UTF-8");
}
urlcon.setDoInput(true); //默认为true
urlcon.setDoOutput(true); //默认为true
//urlcon.connect(); //urlcon.getOutputStream()会隐含的进行connect();
output = new DataOutputStream(urlcon.getOutputStream());
output.writeBytes(content);
output.flush();
output.close();
String str=null;
//if("1".equals(String .valueOf(content.charAt(5)))){
BufferedReader buffer =new BufferedReader(new InputStreamReader(urlcon.getInputStream()));
StringBuffer strBuffer = new StringBuffer();
String str = null;
while((str=buffer.readLine())!=null){
strBuffer.append(str);
}
System.out.println("返回报文为: "+strBuffer);
buffer.close();
//}
urlcon.disconnect();