Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.