Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

HTTP Post with more than 256 chars

by Anonymous Monk
on Mar 22, 2002 at 02:53 UTC ( #153475=perlquestion: print w/replies, xml ) Need Help??

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

Dear Perlmonks Community ...

I spend a lot of hours trying/searching for a right solution for my problem.
With a little script i am scanning my ftp directory, and then want to post this to a bulletin board of mine!

anything works fine, but the post only accept upto 256 chars (ithink)..

I read things about multipart, but couldnt get it run :(

$ua = LWP::UserAgent->new;<br><br> ....<br><br> $response = (new LWP::UserAgent)->request(GET " +rdid=4&styleid=2&subject=test&posticon=images/icons/text.gif&mode=0&s +ubmit=submit&message=@message");<br><br> ...<br><br>
the @message contains the big lines. in the bulletin board it is possible to paste a message with is much more over 256 chars.

My question is how can i post the whole string,not only till 256 chars? Many many thanks!

Greetings, Stefan.

Added code tags dvergin 2002-03-21

Replies are listed 'Best First'.
Re: HTTP Post with more than 256 chars
by gav^ (Curate) on Mar 22, 2002 at 03:03 UTC
    You aren't trying to do a POST you are trying to do a GET, which maybe the limiting factor, though I suspect it is more likely that there is some characters in @message that is causing the proplem. Try either:
    use URI::Escape; my $message = uri_escape(join('', @message));
    Or, more sensibly, a POST request:
    use HTTP::Request::Common qw(POST); use LWP::UserAgent; my $url = ''; my $ua = LWP::UserAgent->new; my $res = $ua->request(POST $url, [action => 'send', boardid => 4]);
    Hope this helps.


Re: HTTP Post with more than 256 chars
by shotgunefx (Parson) on Mar 22, 2002 at 03:16 UTC
    The limit is at least 4096 characters. After that it depends on the server and proxies in between. Try this instead. You don't need multi-part unless you are uploading files, etc
    #!/usr/bin/perl use LWP::UserAgent; use HTTP::Request::Common; my @multi = (1..10); my $ua = new LWP::UserAgent; my $res = $ua->request(GET '', action=>'submit', multi +vals=>[@vals]); if ($res->is_success) { }else{ }
    Though for larger submits, use POST if the program accepts them so your GET doesn't get truncated.


    "To be civilized is to deny one's nature."
    update: sevensven is correct. I should have said "usually at least" instead of "at least 4096".
    Looking through the RFC I noticed this line.
       The HTTP protocol does not place any a priori limit on the length of
       a URI. Servers MUST be able to handle the URI of any resource they
       serve, and SHOULD be able to handle URIs of unbounded length if they
       provide GET-based forms that could generate such URIs. A server
       SHOULD return 414 (Request-URI Too Long) status if a URI is longer
       than the server can handle (see section 10.4.15).
         Note: Servers should be cautious about depending on URI lengths
         above 255 bytes, because some older client or proxy implementations
         may not properly support these lengths.
    This might be biting you even when you correct your code. But you just have to change GET to POST and as long as the server accepts that method, you should be fine.
Re: HTTP Post with more than 256 chars
by dws (Chancellor) on Mar 22, 2002 at 03:10 UTC
    You're confusing and HTTP POST and HTTP GET. A GET request is done via URLs, and is limited in length. What you need to do is to synthesize a POST. Consult the LWP documentation for an example.

      Specifically perldoc lwpcook, under the surprisingly aptly named section POST.

Re: HTTP Post with more than 256 chars
by sevensven (Pilgrim) on Mar 22, 2002 at 18:17 UTC

    gav^ ++ already hit the nail on the head, but just to clarify a common misconception that I've seen around :

    There is no limit in the size of a get request defined in the HTTP 1.0 RFC, nor in the HTTP 1.1 RFC

    What exists is the limitation that each web server/browser chooses to implement. You will find diferent limits in each server. Apache, for instance, comes with a documented default maximum of 8190 bytes for requests in include/httpd.h

    Even the dark side has a way to change this value in his, er, web server.

    So, correct your code. Then, if it is not enough, change your code to POST. And, please, tell the world that there is no limitation in the GET size in the HTTP protocol :-)

    -- sevensven or nana korobi, ya oki

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://153475]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2020-11-27 01:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found