Use the underlying soap body + post method to send soap requests

Source: Internet
Author: User
Tags soap client
We have used php soap extension to establish the server and client programs, and used third-party class libraries to create the wsdl

We have used php's soap extension to establish the server and client programs, and used a third-party class library to create the wsdl.

Server. php (server) Write_log ($ select_ SQL, $ this-> log_file); return $ select_ SQL;}/** function: write logs * $ file_name: log file name * $ string: log content */private function write_log ($ string, $ file_name) {date_default_timezone_set ("Asia/Shanghai"); $ now_time = date ("Y-m-d H: m: s "); $ file_resource = fopen ($ file_name, 'A'); fwrite ($ file_resource, $ now_time. '= '. $ string. "\ r \ n"); fclose ($ file_resource) ;}// generate the soap server $ server = new SoapServer ('service. wsdl ', array ('soa P_version' => SOAP_1_2); $ server-> setClass ("Service"); // register all methods of the Service class $ server-> handle (); // process the request?> ========================================================== ========================================================== ======== Client. php (client) _ SoapCall ('start _ dk ', array (1, 2); echo $ soap_return;?> ========================================================== ========================================================== ======== Service. wsdl) ========================================================== ========================================================== ======== The above three files form a complete web service. Let's talk about an interesting topic today. Can we use a more underlying method to implement php soap communication. The answer is yes. If you know something about soap, you must understand that soap is essentially a text in xml format. http post requests are used as channels to exchange data between the server and the client, so that the request Service can exchange data. Next we will take you to improve client. php and request the server in a more underlying way, which will help you have a deeper understanding of soap. ========================================================== ========================================================== ======== Client. php (client) 1 2 '; // Use curl to send the soap client request to the server $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, "http: // localhost/soap_demo/server. php "); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ soap ); $ data = curl_exec ($ ch); curl_close ($ ch); // The Output Server returns var_dump ($ data);?> ========================================================== ========================================================== ====== Running result UPDATE 'dk _ day_data 'SET 'data _ clear' = 0 WHERE 'DB _ name' = '1' AND 'time' = '2' ========================================================== ========================================================== Yes. The soap request sent using php extension is returned by the soap server method when the soap response is received. The soap request sent using the soap body + post method is the original soap response when the soap response is received. The return value of the method is included in Medium

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.