Sending file to secured SOAP web service using apache http client

我是研究僧i 提交于 2020-01-16 07:18:49

问题


There is a SOAP service written which is for any file transfer. I need to call that service using apache http clientlibrary.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!