| |||||||||||
| |||||||||||
Server response Posted by John_Moylan (jfp), 14 February 2003 Morning allany clues on how to get just the server response from a http request in a cgi script? Looking at redirecting if the response is good ie: 200 or somewhere else if bad (404 etc) Theres got to be an easy way! jfp Posted by admin (Graham Ellis), 14 February 2003 Are you looking at one server from another? Do you have the LWP module loaded on your server? If so, you can use that. The example that I have here is a stand along program, but I've done the same thing wrapped in a CGI script to have various servers talking to each other.Code:
runs: bash-2.04$ ./gresp.pl Response from http://www.wellho.net/index.html was code 200 Response from http://www.wellho.net/greatsite.html was code 404 bash-2.04$ Posted by admin (Graham Ellis), 15 February 2003 Came back this morning and actually read your question ![]() If you replace the GET with HEAD in my code, your script will read back just the header from the server and not the body ... then you'll be able to make your decision whether or not the server has good information at the present time Posted by John_Moylan (jfp), 16 February 2003 Thanks Graham, thats great.Are you aware of a problem with useragent though? it throws a 500 error when the request is valid. What I'm trying to do is get the server repsonse from a password protected page, so the url looks like: Code:
Though it works in the browser the script using useagent throws a 500 eror? strange! Have you encountered this? jfp Posted by admin (Graham Ellis), 17 February 2003 Not a form of URL that I use personally ... but I'm very suprised at the error 500 as it usually indicates a server-side problem and not a fault in the request. However - I would have a detailed look at the request. I've stepped back into some older examples - here is an "echo server" that takes whatever is thrown at it on port 8080 and echos it back as a web page. If you run this against your user agent script, and again using your regular browser, you might spot what's different in the requests and so be lead towards a solution. Code:
and whc_filter.pm Code:
Posted by John_Moylan (jfp), 18 February 2003 Never did get to the bottom of this!Ended up doing a 'wget -S' and regexing the response. This was being done as a quick mockup in Perl, the real thing needs to be written in Java. Is there anything similar to useragent or wget that would give the server response in Java? Thanks jfp Should I be cross posting this to the Java Forum? Posted by John_Moylan (jfp), 18 February 2003 Sorry, sorry sorry.I'm breaking my own rules by posting without looking for myself. A quick look at javadoc points me towards: HttpURLConnection which has a method called getResponseCode() Erm, that'll teach me, the answers always out there...and its normally in the docs, regardless of the language you use. jfp This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |