:::: 개발 ::::/::: JAVA :::

java spring(스프링) xml mashalling (마샬링) 2

nayha 2020. 1. 29. 15:26

음 이건 xml 형태 만들기 귀찮고 전달 형태를 알고 있을때 문자열로 처리

        HttpClient httpclient = HttpClientBuilder.create().build();
		final String parameters = "?name=더미&group=더미2";
		HttpPost httppost = new HttpPost("https://요청URL"+parameters);

		httppost.setHeader(HTTP.CONTENT_TYPE, "application/xml; charset=UTF-8");
        
   		/*전달 XML string*/
		final String msg = "<n0:M015_CusReq xmlns:ns0=\"http://nayha.tistory.com/Customer\">\n" + 
				"    <I_KU>아이쿠</I_KU>\n" + 
				"    <I_NA>아이나</I_NA>\n" + 
				"</ns0:M015_CusReq>";
                
		httppost.setEntity(new StringEntity(msg));
        
        HttpResponse httpResponse = httpclient.execute(httppost);
        
        // 응답영역
        HttpEntity entity = httpResponse.getEntity();
        String res = EntityUtils.toString(entity);
        System.out.println(res);

 

반응형