Jump to content

PHP and SOAP


Vixushr

Recommended Posts

Helo,

I need some help with downloading xml from remote server using SOAP in PHP

 

this is sample SOAP code that i have from server:

 

http://shop.megatrend.com/ClientWebServices/ClientWS.asmx

 

POST /ClientWebServices/ClientWS.asmx HTTP/1.1
Host: shop.megatrend.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://shop.megatrend.com/ClientWebServices/GetProducts"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetProducts xmlns="http://shop.megatrend.com/ClientWebServices/">
      <username>string</username>
      <password>string</password>
      <OIB>string</OIB>
    </GetProducts>
  </soap:Body>
</soap:Envelope>

 

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetProductsResponse xmlns="http://shop.megatrend.com/ClientWebServices/">
      <GetProductsResult>
        <WsProduct>
          <PN>string</PN>
          <Code>string</Code>
          <Name>string</Name>
          <Description>string</Description>
          <Manufacturer>string</Manufacturer>
          <Weight>decimal</Weight>
          <Available>boolean</Available>
          <Stock>int</Stock>
          <Warranty>string</Warranty>
          <Price>decimal</Price>
          <Images>
            <WsImage xsi:nil="true" />
            <WsImage xsi:nil="true" />
          </Images>
          <Descriptions>
            <WsDescriptionData xsi:nil="true" />
            <WsDescriptionData xsi:nil="true" />
          </Descriptions>
        </WsProduct>
        <WsProduct>
          <PN>string</PN>
          <Code>string</Code>
          <Name>string</Name>
          <Description>string</Description>
          <Manufacturer>string</Manufacturer>
          <Weight>decimal</Weight>
          <Available>boolean</Available>
          <Stock>int</Stock>
          <Warranty>string</Warranty>
          <Price>decimal</Price>
          <Images>
            <WsImage xsi:nil="true" />
            <WsImage xsi:nil="true" />
          </Images>
          <Descriptions>
            <WsDescriptionData xsi:nil="true" />
            <WsDescriptionData xsi:nil="true" />
          </Descriptions>
        </WsProduct>
      </GetProductsResult>
    </GetProductsResponse>
  </soap:Body>
</soap:Envelope>

 

this is piece of PHP code that i have that shud handle request:

 

    function megatrend_download() {
    $local = dirname(__FILE__);
    $path = $local."/xml/megatrend.xml";
    $path1 = $local."/xml/megatrend1.xml";
    $request = array('username'=>'xxx','password'=>'xxx','oib'=>'xxx');
    postPage($request,'http://shop.megatrend.com/ClientWebServices/GetProducts');
    $curl2 = curl_init();
    curl_setopt($curl2, CURLOPT_URL, 'http://shop.megatrend.com/ClientWebServices/ClientWS.asmx');
    curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl2, CURLOPT_HEADER, false);
    curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true);
...rest of functions...

 

I am clearly missing something but i just cant get it!

Help!

Link to comment
https://forums.phpfreaks.com/topic/245643-php-and-soap/
Share on other sites

Helo, i am still fighting with it...

 

iw tryed this way

 

function megatrend_download() {
    $local = dirname(__FILE__);
    $path = $local."/xml/megatrend.xml";
    $path1 = $local."/xml/megatrend1.xml";
    $postData = array('username'=>'xxx','password'=>'xxx','OIB'=>'xxx');
    $curl2 = curl_init();
    curl_setopt($curl2, CURLOPT_URL, 'http://shop.megatrend.com/ClientWebServices/ClientWS.asmx');
    curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl2, CURLOPT_HEADER, false);
    curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl2, CURLOPT_POSTFIELDS, $postData); 

 

but still error thit i get is:

 

Server was unable to process request. ---> Data at the root level is invalid. Line 1, position 1.

Link to comment
https://forums.phpfreaks.com/topic/245643-php-and-soap/#findComment-1263845
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.