使用apache http客户端将文件发送到安全的SOAP Web服务

时间:2014-03-26 11:02:21

标签: java web-services soap apache-httpclient-4.x

编写了一个用于任何文件传输的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();
        }
    }

但是,我认为上面的代码不包含安全注意事项以及文件附件代码段。 有人可以告诉我要做的更改,以便在上面的代码中包含这两件事(安全性和文件附件)。

0 个答案:

没有答案