The project needs to send soap messages for some operations. Because the SOAP protocol is built on the HTTP protocol, this problem can also be solved by sending HTTP requests. In addition, the project also needs to consider support for the SSL protocol. Method 1: Use soap: lite (third-party Perl Library) to implement use soap: lite; my $ proxy = 'HTTP: // host: Port /... /...? WSDL '; my $ soap = soap: Lite-> proxy ($ proxy)-> NS ('... '); my $ response = $ soap-> call ('... '); because you do not want to introduce a third-party library, this method is not used later. Method 2: Use lwp to implement Use http: headers; Use http: request;
Use lwp: useragent; my $ Server = '...';
# Get SOAP request format my $ content = '...'; # Set HTTP Header
My $ head = http: headers-> New ();
$ Head-> content_type ('text/XML; charset = UTF-8 '); # Set HTTP request and send it
My $ request = http: Request-> New (post, $ server, $ head );
$ Request-> protocol ('HTTP/1.0 ');
$ Request-> content ($ content );
My $ useragent = lwp: useragent-> New ();
My $ response = $ useragent-> request ($ request); Because lwp is a built-in Perl library, there is no problem of using a third-party library. However, to support the SSL protocol, I/O: Socket: SSL, net: SSL, and other third-party libraries must be introduced. Method 3: use the curl command to implement my $ httpurl = $ argv [0]; my $ result = ""; my $ content = '... '; if ($ httpurl = ~ /^ Https/) {my $ certdir = $ argv [1]; $ result = 'curl-k -- silent -- cacert $ certdir /***. PEM -- Cert $ certdir /***. pem' $ httpurl '-d' $ content '';} else {$ result = 'curl -- silent' $ httpurl'-d' $ content '';} this method depends on the curl command, which provides better SSL support and is easy to implement.
Perl sends SOAP requests