java post请求 application/xml方式

//java post请求 xml
		try {
			String cdnaddress = ConfigUtil.getConfig("cdnaddress");
		    URL wsUrl = new URL(cdnaddress);  
		    
		    HttpURLConnection conn =  (HttpURLConnection) wsUrl.openConnection();  
		      
		    conn.setDoInput(true);//有输入  
		    conn.setDoOutput(true);//有输出  
		    conn.setRequestMethod("POST");  
		    conn.setRequestProperty("Content-Type", "text/xml;charset=utf-8");  
		    //从配置文件取得信息 
		    String correlateID = correlateid;
		    String r = " \n"+
			" \n"+
				" \n"+
					" \n"+
						"" + cmsid +" \n"+
					" \n"+
				" \n"+
			"";
		      
		    OutputStream os = conn.getOutputStream();  
		    os.write(r.getBytes());  
		      
		    InputStream is = conn.getInputStream();  
		      
		    byte[] b = new byte[1024];  
		    int len = 0;  
		    String s1 = "";  
		      
		    while( (len = is.read(b)) != -1){  
		        s1 += new String(b,0,len,"UTF-8");  
		    }  
		    logger.info("通知CDN:"+s1);
		    os.close();  
		    is.close();  
		    conn.disconnect();  
		}
		catch (Exception e) {
			e.printStackTrace();
		}

 

你可能感兴趣的:(java)