问题
There is a SOAP service written which is for any file transfer. I need to call that service using apache http client
library.
First thing to be noted is that the service is secured with password digest. I have username and password.
Second, I need to pass a file as an attachment.
I have come across the following code
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();
}
}
But, i think the above piece of code doesn't include security considerations and also the file attachment piece of code. Can someone please let me know the changes to be done in order to include these two things(security and file attachment) in the above code.
来源:https://stackoverflow.com/questions/22658949/sending-file-to-secured-soap-web-service-using-apache-http-client