编写了一个用于任何文件传输的SOAP服务。我需要使用apache http client
库调用该服务。
首先要注意的是,服务是通过密码摘要来保护的。我有用户名和密码。
其次,我需要将文件作为附件传递。
我遇到过以下代码
void post(String strURL, String strSoapAction, String strXMLFilename) throws Exception{
File input = new File(strXMLFilename);
PostMethod post = new PostMethod(strURL);
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
post.setRequestEntity(entity);
post.setRequestHeader("SOAPAction", strSoapAction);
HttpClient httpclient = new HttpClient();
try {
int result = httpclient.executeMethod(post);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
但是,我认为上面的代码不包含安全注意事项以及文件附件代码段。 有人可以告诉我要做的更改,以便在上面的代码中包含这两件事(安全性和文件附件)。