SOAP request not returning a response - php

I am making a request to a search directory that looks up HIV specialists. Here is the documentation they provide: http://mobile.aahivm.org/getinfo.asmx?op=GetProviders
I use PHP's cUrl to make the request. Any idea why nothing is being returned?
<?php
$curlData = '<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetProviders xmlns="http://localhost">
<fname></fname>
<lname></lname>
<locationzip></locationzip>
<locationcity></locationcity>
<locationstate>New York</locationstate>
<locationcountry></locationcountry>
<primaryservicesid></primaryservicesid>
<credentials></credentials>
<specialty></specialty>
<specialtycare></specialtycare>
<support></support>
<paymentoptions></paymentoptions>
<member></member>
</GetProviders>
</soap12:Body>
</soap12:Envelope>';
$url='http://mobile.aahivm.org/getinfo.asmx?op=GetProviders';
$curl = curl_init();
$length = strlen($curlData);
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl,CURLOPT_HTTPHEADER,array (
'POST /getinfo.asmx HTTP/1.1',
'Host: mobile.aahivm.org',
'Content-Type: application/soap+xml; charset=utf-8',
'Content-Length:'=>$length,
'SOAPAction: "http://localhost/GetProviders"'
));
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);
//$result = substr(curl_exec($curl), 285, -72); ///remove SOAP envelope!
$result = curl_exec($curl);
print_r("Curl result: ".$result."<br><br><hr>");
curl_close ($curl);
$arr2 = array();
$arr2[] = json_decode($result, true);
////
foreach ($arr2 as $key=>$value) {
//echo $value;
$next[] = $value;
foreach ($next as $key=>$value) {
//echo $value;
$next[] = $value;
foreach ($next as $key=>$value) {
echo $key."=".$value."<br />";
}
echo "--<br /><br />";
}
}
/////
?>

Are you looking to retrieve all of the providers in the response?
In their documentation (http://mobile.aahivm.org/getinfo.asmx?op=GetProviders) it says " The placeholders shown need to be replaced with actual values." So im assuming you will need to send with your request, some sort of values for it to search for.
Hope this helps a bit

Related

(Close) PHP with SOAP, server to get xml from request

I'am new hand about soap
I've a client.php code witch send a xml to server.php.
How to read xml to array in my server.php?
I always get the value without the key
Do I using wsdl to parse xml?
But I'm not good at wsdl...
Can someone help me? Thx a lot.
client.php
<?php
$data = '<?xml version = "1.0" encoding = "UTF-8"?>
<inputMessage>
<ns0:BankCollStatusAdviseRq xmlns:ns0 = "http://ns.tcb.com.tw/XSD/TCB/BC/Message/BankCollStatusAdviseRq/01">
<ns0:SeqNo>00000000</ns0:SeqNo>
<ns0:TxnCode>ARROWAPAN095912 </ns0:TxnCode>
<ns0:CollInfo>
<ns0:CollId>006</ns0:CollId>
<ns0:CurAmt>
<ns0:Amt>1000</ns0:Amt>
</ns0:CurAmt>
</ns0:CollInfo>
<ns0:SettlementInfo>
<ns0:SettlementId>0063201924</ns0:SettlementId>
</ns0:SettlementInfo>
</ns0:BankCollStatusAdviseRq>
<headers>
<Header.PartyInfo>
<ns0:PartyInfo xmlns:ns0 = "http://www.tibco.com/namespaces/bc/2002/04/partyinfo.xsd">
<from>
<name>BANK006</name>
</from>
<operationID>BankColl/1.0/BankCollStatusAdvise</operationID>
</ns0:PartyInfo>
</Header.PartyInfo>
</headers>
<ns0:_configData xmlns:ns0 = "http://tibco.com/namespaces/tnt/plugins/soap">
<endpointURL>https://dev.admin.roombook.com.tw/automsgclient_tc.php?wsdl</endpointURL>
<soapAction>/BankColl</soapAction>
</ns0:_configData>
</inputMessage>';
$url = "http://localhost:8080/test/soap/demo2/server.php";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/soap+xml",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
server.php
<?php
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
header($_SERVER["SERVER_PROTOCOL"]." 405 Method Not Allowed", true, 405);
exit;
}
$postData = trim(file_get_contents('php://input'));
echo "<pre>";print_r($postData);echo "</pre>";
libxml_use_internal_errors(true);
$xml = simplexml_load_string($postData);
if($xml === false) {
header($_SERVER["SERVER_PROTOCOL"]." 400 Bad Request", true, 400);
foreach(libxml_get_errors() as $xmlError) {
echo $xmlError->message . "\n";
}
exit;
}
?>

Empty Result Curl in php

I'm having a problem with PHP's cURL returning an empty string with some URL's
i want to coonect this api and i give the empty result, anyone can help me ?
<?php
$clTrid="TEST-23233434343";
$nictoken="6661361102210630";
$contact="Test-irnic";
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<contact:info xmlns:contact="http://epp.nic.ir/ns/contact-1.0">
<contact:id>' . $contact . '</contact:id>
<contact:pw>' . $nictoken . '</contact:pw>
</contact:authInfo>
</contact:check>
</check>
<clTRID>' . $clTrid . '</clTRID>
</command>
</epp>';
$url = 'https://epp.nic.ir/submit';
$curl = curl_init($url);
curl_setopt ($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
}
else echo " No Error ! ";
if(curl_errno($curl)){
throw new Exception(curl_error($curl));
}
curl_close($curl);
echo $result;
var_dump($result);
?>

Parse XML SOAP response php

I'm using the following code to send an request to a SOAP service:
header('Content-type: application/xml');
function doXMLCurl($url,$postXML){
$CURL = curl_init();
curl_setopt($CURL, CURLOPT_URL, $url);
curl_setopt($CURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($CURL, CURLOPT_POST, 1);
curl_setopt($CURL, CURLOPT_POSTFIELDS, $postXML);
curl_setopt($CURL, CURLOPT_HEADER, false);
curl_setopt($CURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($CURL, CURLOPT_HTTPHEADER, array('Accept: text/xml','Content-Type: application/soap+xml'));
curl_setopt($CURL, CURLOPT_RETURNTRANSFER, true);
$xmlResponse = curl_exec($CURL);
return $xmlResponse;
}
$input_xml = '<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">.....</s:Envelope>';
echo doXMLCurl('webservice_url', $input_xml);
The responde is a XML too.
How can i parse this data or convert to an array or object? I tried with simplexml_load_string() but without success.
EDIT
XML Response:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">...</a:Action>
</s:Header>
<s:Body>
<ListStatesResponse xmlns="http://tempuri.org/">
<ListStatesResult xmlns:b="..." xmlns:i="...">
<b:Return>0</b:Return>
<b:Message i:nil="true"/>
<b:Status>00</b:Status>
<b:ListStates>
<b:States>
<b:Description>ACRE</b:Description>
<b:Code>AC</b:Code>
</b:States>
<b:States>
<b:Description>ALAGOAS</b:Description>
<b:Code>AL</b:Code>
</b:States>
<b:States>
<b:Description>AMAZONAS</b:Description>
<b:Code>AM</b:Code>
</b:States>
...
</b:ListStates>
</ListStatesResult>
</ListStatesResponse>
</s:Body>
</s:Envelope>
Assuming the xml is valid, you can use SimpleXMLElement, i.e.:
$xml = new SimpleXMLElement($xmlResponse);
echo $xml->node->otherNode['Id'];
To loop it, use:
foreach ($xml->node->otherNode as $el) {
foreach($el as $key => $val) {
echo "{$key}: {$val}";
}
}
I found the easiest way is to use json functions
$jsonObject = json_decode(json_encode($xmlString));
Then print_r($jsonObject) to find the structure. This allows attributes to be accessible to using $jsonObject->{'#attributes'}->id;

Using XML Data as Array

I have a problem, I'm trying to get data from http://www.acquaintcrm.co.uk/propertyfunctions/propertysearch.asmx?op=GetDataV8
I have made the request and output the data to a file, properties.xml
The file gets filled with data, but I just dont know how to use that data, I would like to convert the xml data into an array, but I honestly don't know where to start.
My code
$xml_data = '<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>
<GetDataV8 xmlns="http://www.AcquaintCRM.co.uk/propertyfunctions/">
<strSitePrefix>STDZ</strSitePrefix>
<intSiteID>-1</intSiteID>
<intPropertyID>0</intPropertyID>
<intPropertyDevelopmentID>0</intPropertyDevelopmentID>
<bytBedrooms>0</bytBedrooms>
<decMinPrice>0</decMinPrice>
<decMaxPrice>0</decMaxPrice>
<bytTenure>1</bytTenure>
<intCommercial>-1</intCommercial>
<bytPropertyAge>0</bytPropertyAge>
<intRentalTerms>0</intRentalTerms>
<bytFeaturedCount>0</bytFeaturedCount>
<strAreas></strAreas>
<strTypes></strTypes>
<bytSortOrder>0</bytSortOrder>
<bytUseCDataTags>0</bytUseCDataTags>
</GetDataV8>
</soap:Body>
</soap:Envelope>
';
$url = "http://www.acquaintcrm.co.uk/propertyfunctions/propertysearch.asmx?op=GetDataV8";
$headers = array(
"POST * HTTP/1.1",
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Content-length: ".strlen($xml_data),
"SOAPAction: http://www.AcquaintCRM.co.uk/propertyfunctions/GetDataV8",
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
$response = curl_exec($ch);
if (curl_errno($ch))
{
echo 'Error: ';
echo curl_error($ch);
}
else
{
curl_close($ch);
$xml = file_put_contents('properties.xml', $response);
$xml = simplexml_load_file('properties.xml');
print_r($xml);
}
The XML file can be viewed here
http://manchester.studentdigz.com/properties.xml
Thank you all in advance, I appreciate all help!
You can use php simplexml (http://php.net/manual/en/book.simplexml.php) to load the string in an object.
Note that if you really want an array you could as well do :
$xml = simplexml_load_string($xmlstring)->children('http://schemas.xmlsoap.org/soap/envelope/')->children('Body');
$json = json_encode($xml);
$array = json_decode($json,TRUE);
echo "<pre>";
echo "xml object : <br/>";
var_dump($xml);
echo "<hr/>";
echo "json string : <br/>";
var_dump($json);
echo "<hr/>";
echo "array : <br/>";
var_dump($array);

How to traverse xml in php

I am using the following function
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$myTestingUrl = file_get_contents_curl("myUrl");
After I run that function I have
$myTestingUrl =
<?xml version="1.0" encoding="UTF-8"?>
<map>
<entry key="keyName">
<entry key="ActionUrl">http://www.my_actionUrl.com/</entry>
</entry>
</map>
Can you please tell me how can I traverse $myTestingUrl to get the content of entry key "ActionUrl" (http://www.my_actionUrl.com/) in a variable in php?
Thank you!
Try
$xml = simplexml_load_string($myTestingUrl );
$items = $xml->xpath('/map/entry/entry[#key="ActionUrl"]/text()');
echo $items[0];
I prefer #air4x's XPath method but here it is without XPath - for the purpose of showing element and attribute access in SimpleXML:
Codepad demo
$obj = simplexml_load_string($myTestingUrl);
foreach($obj->entry as $entry)
{
if(isset($entry->entry))
{
foreach($entry->entry->attributes() as $key => $value)
{
if($key == 'key' && $value == 'ActionUrl')
{
echo 'ActionUrl is: ' . (string)$entry->entry;
break 1;
}
}
}
}

Categories