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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"+
			"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"+
				"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> \n"+
				"<soapenv:Body> \n"+
					"<ns1:ContentDeployReq \n"+
						"soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"+
						" xmlns:ns1=\"iptv\"> \n"+
						"<CMSID xsi:type=\"xsd:string\">" + cmsid +"</CMSID> \n"+
					"</ns1:ContentDeployReq> \n"+
				"</soapenv:Body> \n"+
			"</soapenv:Envelope>";
		      
		    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();
		}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章