PHP cURL Generate Simple HTTP POST Request

Posted: Mei 24, 2016 in PHP
Tag:, , , ,

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 :

$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&#8221;
xmlns:xsd=”http://www.w3.org/2001/XMLSchema&#8221;
xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:urn=”urn:sj_service”>
<soapenv:Header/>
<soapenv:Body>
<urn:WsSearchFlight
soapenv:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”&gt;
<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);
}

 

Monggo di coba dengan url web service anda.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s