가장 간단하게 아파치그룹의 HTTPClient  (참고 URL : http://hc.apache.org/)을 라이브러리를 활용하여 

첨부의 샘플소스와 같이 간단하게 XML 데이터를 송신하는 샘플 소스 생성이 가능함                               

package Network;
package Network;

import java.io.*;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;

public class PostXML {
	public static void main(String[] args) throws Exception {

		String strURL = null;
		// 수신지 URL 셋팅
		strURL = "https://xxx.xxx.xxx.xxx:5400/invoke/wm.tn/receive";

		// Prepare HTTP post
		PostMethod post = new PostMethod(strURL);

		StringBuffer sbOut = new StringBuffer();
		/*-- Sample XML --*/
		// sbOut.append("");
		sbOut.append("");
		sbOut.append("");
		sbOut.append("20090616111724000550_PKEHQ"); // Interface Unique ID
		sbOut.append("TestSender");// Customer System DUNS ID
		sbOut.append("TestReceiver"); // Pantos Logistics DUNS ID
		sbOut.append("CXML_LGE_NW_TEST"); // Interface Document Type ID
		sbOut.append("20090616111724"); // Interface occur time
		sbOut.append("");
		sbOut.append("");
		sbOut.append("");
		sbOut.append("");
		sbOut.append("Y12");
		sbOut.append("A-01-A");
		sbOut.append("sku");
		sbOut.append("24");
		sbOut.append("testid");
		sbOut.append("");
		sbOut.append("");
		sbOut.append("");

		// 전송 Data 셋팅
		InputStream inputStream = new ByteArrayInputStream(sbOut.toString().getBytes());
		post.setRequestEntity(new InputStreamRequestEntity(inputStream));

		// 전송시 권한 체크시 사용ID / PW
		String authInfo = "userid" + ":" + "password";
		String encoding = new sun.misc.BASE64Encoder().encode(authInfo.getBytes());
		post.setRequestHeader("Authorization", "Basic " + encoding);
		// HTTP Content-Type 셋팅
		post.setRequestHeader("Content-Type", "text/xml;charset=KSC5601");

		// Get HTTP client
		HttpClient httpclient = new HttpClient();

		// Execute request
		try {

			int result = httpclient.executeMethod(post);

			// Display status code
			System.out.println("Response status code: " + result);

			// Display response
			System.out.println("Response body: ");
			System.out.println(post.getResponseBodyAsString());

		} finally {
			// Release current connection to the connection pool
			// once you are done
			post.releaseConnection();
		}
	}
}



Posted by INSPIEN
,