Retrieving response headers from an off-site page
| From: | John Gunther | Date: | Mon, 31 Jul 2006 22:36:19 +0000 |
| Subject: | Retrieving response headers from an off-site page | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-239933@lists.php.net to get a copy of this message | ||
I'm trying to programatically retrieve a sales tax lookup page using file_get_contents() but the page doesn't return data unless a session id is first retrieved and then supplied.
You can see how it works as follows:
The first time I send the following request: http://www7.nystax.gov/STLR/stlrHome?street=48%20central%20ave&zip=12472&B1=Lookup%20Address I get an empty form back, and one of the response headers is Set-Cookie with a value of, say, JSESSIONID=0001WQEmZF6tI-yClq4S9_7a8ii:10amela49;Path=/
If I then reload the same URL, the resulting page includes the desired info, probably because the second time one of the request headers is Cookie with a value of JSESSIONID=0001WQEmZF6tI-yClq4S9_7a8ii:10amela49
I want to get the second version of the page, the one with data, using file_get_contents(), but it appears I first have to get the page to return a sessionid and then I have to send it in a Cookie header the second time.
Reading the first GET's response headers and sending the needed request header on the second GET - in combination with file_get_contents() - is just beyond me. Can anyone enlighten me?
John Gunther