ram.mahaseth Posted December 10, 2009 Share Posted December 10, 2009 Hello there, I'm trying to display the data from record of table I created in quickbase.com in my webpage.For this I made appropriate query to quickbase (as suggested in HTTP API Documentation). It gives response in xml format.I later parse it using simpleXMLElement and use the required value. All this works fine when I run the code in local server (I'm using XAMPP, PHP 5.3.0).But it doesnot work when hosted in remote server (PHP 5.2.11). Here is the code to display xml response: <?php //querying the quick base to get xml response to particular report error_reporting(E_ALL); echo "<pre>"; $request = "https://www.quickbase.com/db/bexiahv4m?act=API_DoQuery&ticket=5_bgstwfekp_byrjk4_b_djxbedds8y689c6beqiurhnr54_b737vy85rv2ge_&apptoken=d75hx9nbmacp3jc7si8ezcdb9wgi&qid=7"; $xml = file_get_contents($request); list($version,$status_code,$msg) = explode(' ',$http_response_header[0], 3); // Check the HTTP Status code switch($status_code) { case 200: // Success break; case 503: die('Your call to quickbase failed and returned an HTTP status of 503. That means: Service unavailable. An internal problem prevented us from returning data to you.'); break; case 403: die('Your call to quickbase failed and returned an HTTP status of 403. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.'); break; case 400: // You may want to fall through here and read the specific XML error die('Your call to quickbase failed and returned an HTTP status of 400. That means: Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.'); break; default: die('Your call to quickbase returned an unexpected HTTP status of:'.$status_code); } $career=htmlspecialchars($xml, ENT_QUOTES); echo $career; It works good in local server. But it displays "Your call to quickbase returned an unexpected HTTP status of:" when hosted in remote server. I've been struggling past few days.But could not find out the reason behind it. Please anybody help me out. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/184645-couldnot-access-the-xml-data-from-webservice-query/ Share on other sites More sharing options...
premiso Posted December 10, 2009 Share Posted December 10, 2009 Are you on shared hosting? If so chances are you are not allowed to pull data from remote sites using file_get_contents as most shared hosts have that turned off for security reasons. If this is the case they also tend to have cURL enabled, and you can use that to retrieve the data instead (see the php manual by click on cURL for more information on how to do that). Quote Link to comment https://forums.phpfreaks.com/topic/184645-couldnot-access-the-xml-data-from-webservice-query/#findComment-974816 Share on other sites More sharing options...
MadTechie Posted December 10, 2009 Share Posted December 10, 2009 I believe the problem is more to do with the https, however the solution is almost the same try this <?php //querying the quick base to get xml response to particular report error_reporting(E_ALL); echo "<pre>"; $request = "https://www.quickbase.com/db/bexiahv4m?act=API_DoQuery&ticket=5_bgstwfekp_byrjk4_b_djxbedds8y689c6beqiurhnr54_b737vy85rv2ge_&apptoken=d75hx9nbmacp3jc7si8ezcdb9wgi&qid=7"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //REQUIRED for HTTPS curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $xml = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); //list($version,$status_code,$msg) = explode(' ',$http_response_header[0], 3); $status_code = $info['http_code']; //replacing previous line // Check the HTTP Status code switch($status_code) { case 200: // Success break; case 503: die('Your call to quickbase failed and returned an HTTP status of 503. That means: Service unavailable. An internal problem prevented us from returning data to you.'); break; case 403: die('Your call to quickbase failed and returned an HTTP status of 403. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.'); break; case 400: // You may want to fall through here and read the specific XML error die('Your call to quickbase failed and returned an HTTP status of 400. That means: Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.'); break; default: die('Your call to quickbase returned an unexpected HTTP status of:'.$status_code); } $career=htmlspecialchars($xml, ENT_QUOTES); echo $career; Quote Link to comment https://forums.phpfreaks.com/topic/184645-couldnot-access-the-xml-data-from-webservice-query/#findComment-974830 Share on other sites More sharing options...
ram.mahaseth Posted December 11, 2009 Author Share Posted December 11, 2009 Hey it solved the issue thanks a lot.It is even working on shared hosting of yahoo with PHP 4.3.11. But I'm not able to parse the XML file using simpleXMLElement class. I guess simpleXMLElement is not for the PHP 4. Is there any other equivalent class to parse XML in PHP 4. regards, Ram Quote Link to comment https://forums.phpfreaks.com/topic/184645-couldnot-access-the-xml-data-from-webservice-query/#findComment-975301 Share on other sites More sharing options...
MadTechie Posted December 11, 2009 Share Posted December 11, 2009 SimpleXML is PHP 5 but xml_parse will work just as well Quote Link to comment https://forums.phpfreaks.com/topic/184645-couldnot-access-the-xml-data-from-webservice-query/#findComment-975337 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.