2.泛微OA Webservice SOAP协议访问



1.SOAP请求报文 Request

POST /services/WorkflowService HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.4 Host: 127.0.0.1:8888 Cache-Control: no-cache Pragma: no-cache SOAPAction: "urn:weaver.workflow.webservices.WorkflowService.doCreateWorkflowRequest" Content-Length: 1425 <?xml version="1.0" encoding="utf-8"?> http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> http://webservices.workflow.weaver">8 http://webservices.workflow.weaver">2 http://webservices.workflow.weaver">title.... http://webservices.workflow.weaver"> 3 http://webservices.workflow.weaver"> true jgck jia gong chang ku true true zjrq zhi jing ri qi true 8

2.SOAP响应报文   Response

HTTP/1.0 200 OK
Server: WVS
Cache-Control: no-cache
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Set-Cookie: ecology_JSessionid=aaaFiDBaNSl5g41CfwX5x; path=/
Content-Type: text/xml; charset=UTF-8
Date: Wed, 19 Jan 2022 08:20:04 GMT

<?xml version="1.0"?>

    
        
            4011
        
    

 3.代码实现

package aaaaaaaaaaaaaaa;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class CURL {

    public static void main(String[] args) throws Exception {
        
        
        URL url=new URL("http://127.0.0.1:8888/services/WorkflowService");
        //创建一个HttpURLConnection对象
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        //设置content-type
        //服务端是soap1.2的协议
        connection.setRequestProperty("Content-Type", " application/soap+xml; charset=utf-8;");
        //设置使用connection对象进行输入输出
        connection.setDoInput(true);
        connection.setDoOutput(true);
        
        connection.getOutputStream().write(getRequestBody().getBytes());
        
        //接收服务端响应的内容
        InputStream in = connection.getInputStream();
        
        byte[] buffer=new byte[2048];
        int len=0;
        
        StringBuilder sb=new StringBuilder();
        
        while((len=in.read(buffer))!=-1)
        {
            String str=new String(buffer,0,len);
            sb.append(str);
        }
        
        in.close();
        
        System.out.println(sb.toString());

    }
    
    //拼接 SOAP请求报文
    private static String getRequestBody() {
        String xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "\n" +
                "    \n" +
                "        \n" +
                "            \n" +
                "                8\n" +
                "                \n" +
                "                2\n" +
                "                \n" +
                "                title....\n" +
                "                \n" +
                "                \n" +
                "                    3\n" +
                "                \n" +
                "                \n" +
                "                    \n" +
                "                        \n" +
                "                            \n" +
                "                                \n" +
                "                                    true\n" +
                "                                    jgck\n" +
                "                                    jia gong chang ku\n" +
                "                                    true\n" +
                "                                \n" +
                "                                \n" +
                "                                    true\n" +
                "                                    zjrq\n" +
                "                                    zhi jing ri qi\n" +
                "                                    true\n" +
                "                                \n" +
                "                            \n" +
                "                        \n" +
                "                    \n" +
                "                \n" +
                "            \n" +
                "            8\n" +
                "        \n" +
                "    \n" +
                "";
        return xml;
    }
    
    
    

}