Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi for some reasons I can't submit this little, simple form with Perl:
<FORM ACTION="/sms/austria.php3" METHOD="post" NAME="austria"> <SELECT SIZE="1" NAME="austria"> <OPTION VALUE="error" SELECTED>select Net</OPTION> <OPTION VALUE="43664">0664 (A1)</OPTION> <OPTION VALUE="43676">0676 (T-Mobile)</OPTION> <OPTION VALUE="43699">0699 (ONE)</OPTION> <OPTION VALUE="43650">0650 (tele.ring)</OPTION> </SELECT> <INPUT TYPE="image" SRC="/images/sms/weiter.gif" ALT="weiter" NAME="i +mage" BORDER="0"> </FORM>
I set 'austria' to '43699'. $form1->dump gives this:
POST http://subscriber.chello.at/sms/austria.php3 austria=43699 (option) [error|43664|43676|*43699|43650] image=<UNDEF> (image)
Now I tried various ways to click this form:
$res = $ub->request($form[1]->click()); $res = $ub->request($form[1]->click('image')); $res = $ub->request($form[1]->click('image',0,0)); $res = $ub->request(POST $URL, @TEL);
with:
@TEL = [austria, '43699', 'image.x', '0', 'image.y', '0']; ( or @TEL = [austria, '43699']; ) $URL = 'http://subscriber.chello.at/sms/austria.php3';
In Perl I always get an empty response:
_msg => Found _rc => 302 _content =>
The Hash of '_request' looks like:
Request: _method => POST _headers => HTTP::Headers=HASH(0x84e0cc4) _uri => http://subscriber.chello.at/sms/austria.php3 _content => austria=43699&image.x=0&image.y=0
Using Lynx I can fillout and successfully submit this form. Trace gives me this entries:
GridText - post_data: austria=43699&image.x=0&image.y=0 .. LYpush[0]: address:http://subscriber.chello.at/sms/index.php3 title:hello, i'm chello getfile: getting http://subscriber.chello.at/sms/austria.php3
Does anybody has a hint who I can go on or what I should try to submit this with Perl?

Thanks to all in advance,
Carl

Replies are listed 'Best First'.
Re: submit Form with Lynx but not Perl?
by grantm (Parson) on Aug 05, 2002 at 21:44 UTC

    It looks like your form is being submitted correctly from Perl, and the server response is to redirect you to another URL (response code = 302). You'll need to get the URL out of the 'Location' header of the response object and retrieve that.

    Lynx is following the redirect automatically. You can might want to look at the redirect_ok method of LWP::UserAgent to get similar behaviour

      Thanks for th reply, but allowing redirection does not solve the problem. While Lynx get the next page - the Perl-program gets again the initial page.
      Could it be that Lynx writes a coockie on the server, while Perl doesn't do that? Lynx is set that it does not accept any cookie - so no cookie is written on my computer.

      This is from Lynx:

      LYCookie: Searching for 'subscriber.chello.at:80', '/sms/index.php3'. Composing Authorization for subscriber.chello.at:80/sms/index.php3 HTAASetup_lookup: No template matched `sms/index.php3' (so probably no +t protected) HTTP: Not sending authorization (yet). Writing: GET /sms/index.php3 HTTP/1.0 Host: subscriber.chello.at .... ---------------------------------- HTTP Request is sent. HTTP: WRITE delivered OK HTTP Request sent; waiting for answer. HTTP: Trying to read 1535 HTTP: Read 1448 HTTP: Rx: HTTP/1.1 200 OK HTTP: Scanned 2 fields from line_buffer --- Talking HTTP1. HTTP/1.1 200 OK .... Connection: close
      this I got using Perl (I set in Perl the User-Agent to Lynx 2.8.4rel.1, it could be ...):
      _protocol => HTTP/1.1 _request => HTTP::Request=HASH(0x84e226c) _headers => HTTP::Headers=HASH(0x84e8fac) _previous => HTTP::Response=HASH(0x84dfda0) _msg => OK _rc => 200
      The content of the response (rc=200) is the initial web-page. It is not the next form to enter the sms text.

      Here are the Information of Previous, Headers and Request:

      Previous: _protocol => HTTP/1.1 _request => HTTP::Request=HASH(0x84e22a8) _headers => HTTP::Headers=HASH(0x84dfd94) _rc => 302 _msg => Found _content => Previous-Headers: client-transfer-encoding => chunked client-response-num => 1 location => /sms/index.php3 content-type => text/html server => Apache/1.3.26 (Unix) PHP/4.2.1 connection => close date => Tue, 06 Aug 2002 09:28:00 GMT x-powered-by => PHP/4.2.1 client-date => Tue, 06 Aug 2002 09:28:00 GMT Previous-Request: _method => POST _headers => HTTP::Headers=HASH(0x84e229c) _uri => http://subscriber.chello.at/sms/austria.php3 _content => austria=43699&image.x=0&image.y=0 Previous-Request-Headers: user-agent => Lynx/2.8.4rel.1 content-type => application/x-www-form-urlencoded content-length => 33 - - - - - - Request: _method => POST _headers => HTTP::Headers=HASH(0x84dfaac) _uri => http://subscriber.chello.at/sms/index.php3 _content => austria=43699&image.x=0&image.y=0 Request-Headers: user-agent => Lynx/2.8.4rel.1 content-type => application/x-www-form-urlencoded content-length => 33 - - - - - - Headers: client-transfer-encoding => chunked client-response-num => 1 title => hello, i'm chello content-type => text/html server => Apache/1.3.26 (Unix) PHP/4.2.1 x-meta-author => chello broadband B.V 1999 date => Tue, 06 Aug 2002 09:28:05 GMT connection => close x-powered-by => PHP/4.2.1 link => </dhtml/style/sliding.css>; rel="stylesheet"; type="text/css" client-date => Tue, 06 Aug 2002 09:28:10 GMT

        No, it's not a cookie problem - I can't see any cookie headers in your trace output (and as you say, you have cookies disabled in Lynx anyway).

        Since you're being redirected back to the original page, it looks like there is something wrong with your initial request. My approach would be to use a tool like tcpdump on Linux or Analyzer on Windows to trace the network and compare the Lynx request to the LWP request.