Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用SSL在ApacheHttpClient中发送SOAP请求时出现问题_Soap_Ssl_Apache Httpclient 4.x - Fatal编程技术网

使用SSL在ApacheHttpClient中发送SOAP请求时出现问题

使用SSL在ApacheHttpClient中发送SOAP请求时出现问题,soap,ssl,apache-httpclient-4.x,Soap,Ssl,Apache Httpclient 4.x,我想通过SSL向SOAP服务器Microsoft IIS服务器发送SOAP请求。当我使用SSL密钥库配置通过soapUI工具测试SOAP请求时,它会正确返回响应。但是使用下面的代码,它返回HTTP/1.1400错误请求 我使用了httpclient-4.2.3和httpcore-4.2.2 import java.security.KeyStore; import org.apache.http.Header; import org.apache.http.HttpEntity;

我想通过SSL向SOAP服务器Microsoft IIS服务器发送SOAP请求。当我使用SSL密钥库配置通过soapUI工具测试SOAP请求时,它会正确返回响应。但是使用下面的代码,它返回HTTP/1.1400错误请求 我使用了httpclient-4.2.3和httpcore-4.2.2

import java.security.KeyStore;    
import org.apache.http.Header;    
import org.apache.http.HttpEntity;    
import org.apache.http.HttpResponse;    
import org.apache.http.client.methods.HttpGet;    
import org.apache.http.client.methods.HttpPost;    
import org.apache.http.conn.scheme.Scheme;    
import org.apache.http.conn.scheme.SchemeRegistry;    
import org.apache.http.conn.ssl.SSLSocketFactory;    
import org.apache.http.entity.StringEntity;    
import org.apache.http.impl.client.DefaultHttpClient;    
import org.apache.http.impl.conn.BasicClientConnectionManager;    
import org.apache.http.params.BasicHttpParams;    
import org.apache.http.params.HttpParams;    
import org.apache.http.util.EntityUtils;


public final static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {

        KeyStore keyStore  = KeyStore.getInstance("JKS");
        FileInputStream instream1 = new FileInputStream(new File("C:\\CCDKeyStore\\mykeystore.jks"));
        try {
            keyStore.load(instream1, "1214524".toCharArray());

        } finally {
            try { instream1.close(); } catch (Exception ignore) {}
        }

        SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore,"1214524");
        Scheme sch = new Scheme("https", 443, socketFactory);
        SchemeRegistry schemeRegistry = httpclient.getConnectionManager().getSchemeRegistry();
        schemeRegistry.register(sch);

        final HttpParams httpParams = new BasicHttpParams();
        DefaultHttpClient lHttpClient = new DefaultHttpClient(new BasicClientConnectionManager(schemeRegistry), httpParams);

        String lUrl = "https://api.demo.server.com/XDS/Service.svc?wsdl";

        StringBuffer lXmlBuffer = new StringBuffer();

        lXmlBuffer.append("<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">\n");
        lXmlBuffer.append("<s:Header>\n");
        lXmlBuffer.append("<a:Action s:mustUnderstand=\"1\">urn:74347:4757:StoredQuery</a:Action>\n");
        lXmlBuffer.append("<a:MessageID>urn:uuid:c6430690-412e-4744-afe1-233e2138f2d2</a:MessageID>\n");
        .
        .
        .
        .
        .
        .
        lXmlBuffer.append("</Slot>\n");
        lXmlBuffer.append("</AdhocQuery>\n");            
        lXmlBuffer.append("</query:AdhocQueryRequest>\n");
        lXmlBuffer.append("</s:Body>\n");
        lXmlBuffer.append("</s:Envelope>\n");        


        String lXml = lXmlBuffer.toString();


        HttpPost lMethod = new HttpPost(lUrl);
        HttpEntity lEntity = new StringEntity(lXml, "multipart/related", "utf-8");

       lMethod.setHeader("SOAPAction", "urn:74347:4757:StoredQuery");
       System.out.println(EntityUtils.toString(lEntity));
       lMethod.setEntity(lEntity);

        HttpResponse lHttpResponse = lHttpClient.execute(lMethod);




        } finally {

            httpclient.getConnectionManager().shutdown();
        }
在这方面的任何帮助都非常感谢

谢谢,
默翰

我终于找到了答案

在这里,上面代码中的下一行包含多部分/相关的内容类型。但是web服务应该是内容类型application/soap+xml,因为这是soap请求。请参阅以了解更多信息


HttpEntity-Lenty=新StringEntitylXml,多部分/相关,utf-8

您确定SOAP信封格式正确吗?是的,当我将上述类生成的相同SOAP请求复制并传递到soapUI时,它会正确返回响应。。。