How to post SOAP Request from PHP

后端 未结 7 748
野趣味
野趣味 2020-12-01 03:39

Anyone know how can I post a SOAP Request from PHP?

相关标签:
7条回答
  • 2020-12-01 04:17

    I needed to do many very simple XML requests and after reading @Ivan Krechetov's comment about the speed hit of SOAP, I tried his code and discovered http_post_data() is not built into PHP 5.2. Not really wanting to install it, I tried cURL which is on all my servers. Although I do not know how fast cURL is compared to SOAP, it sure was easy to do what I needed. Below is a sample with cURL for anyone needing it.

    $xml_data = '<?xml version="1.0" encoding="UTF-8" ?>
    <priceRequest><customerNo>123</customerNo><password>abc</password><skuList><SKU>99999</SKU><lineNumber>1</lineNumber></skuList></priceRequest>';
    $URL = "https://test.testserver.com/PriceAvailability";
    
    $ch = curl_init($URL);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    
    
    print_r($output);
    
    0 讨论(0)
提交回复
热议问题