<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 我还得到了以下方法:
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 服务器的动态 Web 项目。我还被告知要获取 org.apache.commons.httpclient 库。
我一直试图把这些碎片拼凑起来,但我失败了。我收到错误:getHttpClient(),说该方法无法解析。日志相同,无法解决 InvalidRequestException。看来我必须将我的类扩展到另一个包含这三种方法的类。可能是哪个班?我可能会丢失哪些罐子?调用上述方法并传递所需参数的简单 main 方法会起作用吗?