PHP w/ cURL Example

From CDYNE Wiki
Jump to navigation Jump to search

CheckPhoneNumber

 1 <?php
 2 
 3 $xml='<?xml version="1.0" encoding="utf-8"?>
 4 <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/">
 5   <soap:Body>
 6     <CheckPhoneNumber xmlns="http://ws.cdyne.com/PhoneVerify/query">
 7       <PhoneNumber>17575449510</PhoneNumber>
 8       <LicenseKey> f01d89fd-5155-5455-5585-e84ab8de8591</LicenseKey>
 9     </CheckPhoneNumber>
10   </soap:Body>
11 </soap:Envelope>';
12  
13 $headers = array(
14 "POST  HTTP/1.1",
15 "Host: ws.cdyne.com",
16 "Content-type: text/xml; charset=\"utf-8\"",
17 "SOAPAction: \"http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber\"");
18  
19 $url = "http://ws.cdyne.com/phoneverify/phoneverify.asmx?op=CheckPhoneNumber";
20  
21 $ch = curl_init();
22 curl_setopt($ch, CURLOPT_URL,            $url );
23 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
24 curl_setopt($ch, CURLOPT_POST,1 );
25 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
26 curl_setopt($ch, CURLOPT_POSTFIELDS,    $xml);
27 $response = htmlspecialchars(curl_exec($ch));
28 curl_close($ch);
29 print_r($response);
30 
31 ?>