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

I need a help with Posting a form with following input
<input name="/process.create" value="loc=AL&cat=4">
I have tried 2 different ways but they both cause an error.
$request = POST 'http://www.server.com', Content => [ /process.create +=> 'loc=AL&cat=4' ]; my $response = $ua->request($request);
This causes a syntax error because of the "/" or "." in the field name.
$contentdata = '/process.create=loc=AL&cat=4'; $encoded = uri_escape($contentdata); $request = new HTTP::Request('POST', 'www.server.com'); $request->content_type('application/x-www-form-urlencoded'); $request->content($encoded); my $response = $ua->request($request);
This doesn't cause any errors but when the server receives the data, it treats "/process.create" and "cat" as two different fields because of "&" that's in between. Is there anyway I can post this form? Thanks in advance.

Replies are listed 'Best First'.
Re: LWP & POST
by MeowChow (Vicar) on Feb 15, 2001 at 12:31 UTC
    Your first instinct was correct. You should let POST do the work of creating your content for you. The mistake is in the way you specify your request to the POST method of Http::Request::Common. From your code, it looks like it should be:
    $request = POST 'http://www.server.com/process.create', [ loc => 'AL +', cat => '4' ]; ...
    You specify not the server name, but the full request URL as the first parameter to POST. The second parameter to POST is an anonymous array of the the request's key => value pairs. You should also know that Perl will allow barewords on the left side of the => operator, but barewords don't permit characters like "." and "/".
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      Thanks but perhaps you misunderstood my question. The form I need to post looks like this.
      <form action="www.server.com/form.html"> <input name="/process.create" value="loc=AL&cat=4"> </form>
      The name of the parameter has to be "/process.create" and the value is "loc=AL&cat=4". I don't know why they did it this way but that's what I have to post. Is there anyway for me to post this form via LWP?
        Then the following should work:
        $request = POST 'http://www.server.com/form.html', [ 'process.create +' => 'loc=AL&cat=4' ];
           MeowChow                                   
                       s aamecha.s a..a\u$&owag.print
Re: LWP & POST
by extremely (Priest) on Feb 15, 2001 at 20:27 UTC
    Just to clear up MeowChow's answer, the => acts like a comma AND tries to quote the word to its left. If you confuse the parser into not knowing that it is reading a word, it doesn't know what to quote and it complains and dies. Basically if your words are going to have characters other than a-zA-Z0-9_- in them, go ahead and quote it manually and save yourself and the parser some worry.

    --
    $you = new YOU;
    honk() if $you->love(perl)