<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"^M
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"^M
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"^M
xmlns:xsd="http://www.w3.org/2001/XMLSchema"^M
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">^M
<env:Header>^M
<wsse:Security>^M
<wsse:UsernameToken>^M
<wsse:Username>user</wsse:Username>^M
<wsse:Password>pass</wsse:Password>^M
</wsse:UsernameToken>^M
</wsse:Security> ^M
</env:Header>
이 나는이 XML을 게시했다되었습니다 https://www.abc.com 또한 다음과 같은 방법을 제공하고있다 : 나는 말되었다자바에서 HTTPS를 통해 XML을 게시하는 방법은 무엇입니까?
public int sendPostRequest(String url, String content, String contentType)
throws Exception {
PostMethod post = new PostMethod(url);
post.setRequestEntity(new StringRequestEntity(content, contentType,
null));
boolean success = false;
String responseBody = null;
int statusCode;
try {
getHttpClient().executeMethod(post);
success = true;
statusCode = post.getStatusCode();
responseBody = post.getResponseBodyAsString();
} catch (Exception ex) {
log.error("Marhsalling exception : " + ex.getMessage());
throw new InvalidRequestException("Marhsalling exception :"
+ ex.getMessage());
} finally {
post.releaseConnection();
}
if ((statusCode != HttpStatus.SC_OK) &&
(statusCode != HttpStatus.SC_NO_CONTENT)) {
String error = "Got Bad Http Status - <" + statusCode
+ "> Info : " + responseBody;
log.error(error);
throw new InvalidRequestException(error);
} else {
log.debug("Success - " + responseBody);
}
return statusCode;
}
private String footer = "</env:Envelope>";
private String message = "<InstallService><NewAccount></NewAccount></InstallService>";
private String payload = header + message + footer;
헤더 내가 게시 한 XML입니다. 내용 유형이 확실하지 않아 XML 일 수 있다고 제안되었습니다. 프로젝트 유형은 Tomcat 서버를 사용하는 동적 웹 프로젝트 여야합니다. 나는 또한 org.apache.commons.httpclient 라이브러리를 잡으라고했다.
나는 조각들을 모으려고했지만 나는 실패하고있다. getHttpClient()에서 오류가 발생하여 메서드를 확인할 수 없다는 오류가 발생했습니다. 로그에 대해서도 동일하고 InvalidRequestException을 해결할 수 없습니다. 클래스를이 세 가지 메서드를 포함하는 다른 클래스로 확장해야하는 것으로 보입니다. 어떤 계급이 될 수 있습니까? 어떤 항아리를 놓칠 수 있습니까? 위의 메서드를 호출하고 필요한 인수를 전달하는 간단한 기본 메서드가 작동할까요?
자신 만의 SOAP 클라이언트 API를 작성하려고하는 것 같습니다. SOAP에는 본문 페이로드 외에 HTTP 헤더 요구 사항이 있습니다. 일부 문서 링크는 [here] (http://illegalargumentumentception.blogspot.co.uk/2011/04/java-jax-ws-web-services-and-clients.html#ws_doc)를 참조하십시오. 그러나 Java SOAP 라이브러리 (예 : JAX-RPC; JAX-WS) 활용을 고려하십시오. – McDowell
일부 코드를 제게 보여 주면 좋을 것입니다. –
@Nomain Arain - [질문 10671494] (http://stackoverflow.com/questions/10671494/sending-http-post-request-with-soap-action-using-org-apache-http) 도움이 될 수 있습니다. 그러나 아무것도 처리하지 않으면 오류 처리를 위해 [JAX-WS] (http://illegalargumentumentception.blogspot.co.uk/2011/04/java-jax-ws-web-services-and-clients.html) 클라이언트 API를 사용하는 것이 좋습니다. 그밖에. 수동 HTTP 코드로 SOAP 메시지를 올바르게 처리하려면 사양을 읽고 구현하는 것 외에 다른 방법이 없습니다. – McDowell