You need to make sure that the URL to the PHP file is in the exact domain and sub-domain that the original HTML file is served from. For instance, if you serve the HTML file from http://www.domain.com/index.html then the PHP would be required to be served from http://www.domain.com and not xml.domain.com or even something like www.domain.com/xml. if you even changed the sub-domain, that would be considered by the browser to not be of the same source. So to fix your problem, simply server the PHP proxy from the same directory as the original HTML file making the call. I hope that made sense.
Todd Daniell -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Thursday, October 11, 2007 9:08 PM To: iPhoneWebDev Subject: Re: XMLHTTP Support Thanks Ishan, That site was very useful, but I don't have access to the file that needs to be edited, so I need to use a PHP proxy. The proxy doesn't work, so I will post my code and see if anyone can crack the code. I have entered the url proxy.php?path=http://live.nhl.com/data/ scr20053.txt?i=1192150735281, which shows a blank page, directly accessing the url shows this http://live.nhl.com/data/scr20053.txt?i=1192150735281 <?php // Hardcode the hostname define('HOSTNAME', 'http://live.nhl.com'); // Get the REST call path from the AJAX application $path = $_GET['path']; // The URL to fetch is the hostname + path $url = HOSTNAME.$path; // Open the Curl session $session = curl_init($url); // Don't return HTTP headers. Do return the contents of the call curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Make the call $xml = curl_exec($session); // The web service returns XML header("Content-Type: text/xml"); echo $xml; curl_close($session); ?> On Oct 11, 1:12 pm, "Ishan Anand" <[EMAIL PROTECTED]> wrote: > Kris, > > You might find it easier to do this using Apache's built in mechanisms to > build a reverse proxy than using PHP. For an example visit:http://premshree.livejournal.com/66129.html > > Best, > Ishan > > On 10/11/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > How would you recommend going about redirecting the requests. I have > > basically go experience with PHP (other that echo). I would appreciate > > if you could help me out, but if not I'm sure I would be able to find > > something about it on Google. > > > On Oct 11, 11:44 am, craig <[EMAIL PROTECTED]> wrote: > > > Unless the NHL data and your web app are served from the same domain, > > > you cannot do an XMLHTTPRequest. For security, so-called "cross-site" > > > requests are not allowed (ie, a web app served from mydomain.com > > > cannot do an XMLHTTPRequest for data from yourdomain.com). You > > > somehow will need to host the data on your own site (same domain as > > > where the app lives), or use PHP/etc to redirect local requests to the > > > NHL site. This is a fairly common, but easily handled, limitation of > > > using XMLHTTPRequest. It just requires some server-side workarounds. > > > For my app, I use PHP to handle it. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en -~----------~----~----~----~------~----~------~--~---
