Php cUrl Http Request

PHP cURL HTTP Request

Apa itu cURL ?, Curl adalah sebuah program yang memungkinan kita memindai data dari atau ke sebuah server tanpa interaksi dari masing-masing user.

Script awal yang akan kita coba adalah me-load sebuah halaman web, memindai kontennya, dan mencetak kembali. dalam SOAP request ada 3 hal yang perlu di pahami

  1. Action
  2. Header
  3. Body

Langsung aja ya :

<?php
$url = “https://xxx.com/index.php?wsdl”;
$header = array(
  ‘Accept: */*’,
  ‘Accept-Language: en-us’,
  ‘Content-Type: text/xml; charset=utf-8’,
  “Cache-Control: no-cache”,
  “Pragma: no-cache”,
  “SOAPAction: ‘urn:WsSearchFlight'”,
);
 
$soap_request = ‘<soapenv:Envelope 	xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:xsd=”http://www.w3.org/2001/XMLSchema”
xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:urn=”urn:sj_service”>
  <soapenv:Header/>
  <soapenv:Body>
  	<urn:WsSearchFlight
soapenv:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”>
  		<param xsi:type=”urn:reqWsSearchFlight” xmlns:urn=”urn:webservice”>
 
  		</param>
  	</urn:WsSearchFlight>
  </soapenv:Body>
</soapenv:Envelope>’;
 
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 1000);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 1000);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
 
if(curl_exec($soap_do) === false) {
  $err = ‘Curl error: ‘ . curl_error($soap_do);
  curl_close($soap_do);
  print $err;
} else {
  $info = curl_exec($soap_do);
  curl_close($soap_do);
  print ‘Operation completed without any errors<br>’;
  print_r($info);
}
 
 
?>

good luck …!