Welcome, Guest. Please login or register.

Author Topic: Posting XML data to aspx script using PHP  (Read 6398 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show all replies
Posting XML data to aspx script using PHP
« on: November 04, 2009, 09:24:07 PM »
I've been trying to figure this out for ages, but just can't get my head around it. I'm trying to write a script which will generate a PDF copy of the Metro newspaper. As far as I can tell, their Flash application posts the data contained in the following file:

http://e-edition.metro.co.uk/YYYY/MM/DD/edition.xml

(with YYYY, MM and DD set to the desired date), to the following script:

http://edition.pagesuite-professional.co.uk/create_pdf.aspx?

which then generates the PDF and returns HTML code providing a link to the file. The file is generated on the fly with a name which does not correspond to anything guessable, so the script has to be run. In other words, there is no existing PDF you can hotlink to.

I can't for the life of me figure out how this is done. I've used Firebug to capture the POST request, and the details are below. There is quite a bit about this on the Internet, but most of the examples I found rely on PHP extensions which only seem to work on Windows, or are non-working pseudo-code.


Headers:
Response Headers
Server   Microsoft-IIS/6.0
X-Powered-By   ASP.NET
X-AspNet-Version   2.0.50727
Cache-Control   private
Content-Type   text/html; charset=utf-8
Content-Length   226
Date   Wed, 04 Nov 2009 20:10:06 GMT
Connection   keep-alive
Vary   Accept-Encoding

Request Headers
Host   edition.pagesuite-professional.co.uk
User-Agent   Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-GB; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
Accept   text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language   en-gb,en;q=0.5
Accept-Encoding   gzip,deflate
Accept-Charset   ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive   300
Connection   keep-alive
Referer   http://e-edition.metro.co.uk/2009/11/04/


Data:
Content-type: application/xml
Content-length: 2415

Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show all replies
Re: Posting XML data to aspx script using PHP
« Reply #1 on: November 04, 2009, 11:02:21 PM »
Metro fans, rejoice! The following works.

<?php

$year
=date('Y');
$month=date('m');
$day=date('d');

$xml file_get_contents("http://e-edition.metro.co.uk/$year/$month/$day/edition.xml");

$ch curl_init(); //initiate the curl session
curl_setopt($chCURLOPT_URL"http://edition.pagesuite-professional.co.uk/create_pdf.aspx?"); //set to url to post to
curl_setopt($chCURLOPT_RETURNTRANSFER1); // tell curl to return data in a variable
curl_setopt($chCURLOPT_HEADER0);
curl_setopt($chCURLOPT_POST1);
curl_setopt($chCURLOPT_POSTFIELDS$xml); // post the xml
curl_setopt($chCURLOPT_TIMEOUT5); // set timeout in seconds
$xmlResponse curl_exec ($ch);
curl_close ($ch);

$start=strpos($xmlResponse"http");
$url=substr($xmlResponse$start);
$end=strpos($url".pdf");
$url=substr($url0$end+4);

echo 
"<a href='" $url "'>Click here to download the Metro</a>";

?>
« Last Edit: November 04, 2009, 11:09:13 PM by motorollin »
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show all replies
Re: Posting XML data to aspx script using PHP
« Reply #2 on: July 11, 2010, 02:56:29 PM »
Just tested and it still works for me. As Karlos said make sure you have correctly configured the PHP service on your web server, and also only use it on a date when there was actually a Metro published. The script uses the current date as part of the URL string for the current issue, and will get a 404 if you run it on a Saturday or Sunday. If you want to test the script on a weekend you can force it to download a particular issue by manipulating the $xml variable like this:

Code: [Select]
$xml = file_get_contents(&quot;http://e-edition.metro.co.uk/2010/07/09/edition.xml&quot;);

which would download the issue from Friday just gone (the 9th of July 2010).

--
moto
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10