Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2019
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2. $username = "utente";
  3. $password = "Password";
  4. $apiKey = "chiaveApi";
  5. $url = "https://www.brandsdistribution.com/";
  6. //$url = "https://idt2015.rewix.zero11.net/";  #SandBox
  7.  
  8. $url .= "restful/export/api/products.xml";
  9. $query = http_build_query([
  10.         'acceptedlocales' => 'it_IT',
  11.         'output-file' => 'xml',
  12.         'since' => date("Y-m-d\TH:i:sO")
  13. ]);
  14.  
  15. $url = "$url?".$query;
  16. echo $url;
  17. $header = "Authorization: Basic " . base64_encode($apiKey . ':' . $password);
  18. $xmlstr = <<<XML
  19. <?xml version='1.0' standalone='yes'?>
  20. <operations>
  21. </operations>
  22. XML;
  23. $xml = new SimpleXMLElement($xmlstr);
  24.  
  25. $xmlOperation = $xml->addChild('operation');
  26. $xmlOperation->addAttribute(‘type’, ‘lock’);
  27.  
  28. $xmlModel = $xmlOperation->addChild('model');
  29. $xmlModel->addAttribute(‘stock_id’, 1);
  30. $xmlModel->addAttribute(‘quantity’, 1);
  31.  
  32. $xmlText = $xml->asXML();
  33.  
  34.  
  35. $ch = curl_init($url);
  36. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  37. curl_setopt($ch, CURLOPT_USERPWD, ($username . ':' . $password));
  38. curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: application/xml','Accept: application/xml',$header));
  39. curl_setopt($ch, CURLOPT_POST, 1);
  40. curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlText);
  41. $data = curl_exec($ch);
  42. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  43. curl_close($ch);
  44. echo $data;
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement