curl-users
Re: post textarea field with the content from a text file
Date: Wed, 04 Oct 2006 16:58:35 -0400
thank you very much, after a small modification, it worked!
Qianqian
#!/usr/bin/perl
use strict;
my $file=$ARGV[0];
my $title=$ARGV[1];
my $summary=$ARGV[2];
my $url=$ARGV[3];
my @content;
my $text;
my $oldtime;
if($url eq "") {
$url="http://ntroi.nmr.mgh.harvard.edu/review/index.cgi";
}
open (FIN,"<$file") || die("can not open file $file");
@content=<FIN>;
close(FIN);
$text=&UrlEncode2(join("",@content));
$oldtime=time;
open (TEST,">/tmp/wikiintmp") || die("can not write");
print TEST "text=$text";
close(TEST);
system("curl -d 'oldtime=$oldtime' -d 'title=$title' -d
'summary=$summary' -d 'Save=Save' -d @/tmp/wikiintmp '$url'");
sub UrlEncode2 {
my $str = shift;
return '' unless $str;
my @letters = split(//, $str);
my @unsafe = ('\'','&','+','?',';',"\n");
foreach my $letter (@letters) {
my $pattern = quotemeta($letter);
if (grep(/$pattern/, @unsafe)) {
$letter = sprintf("%%%02X", ord($letter));
}
}
return join('', @letters);
}
Daniel Stenberg wrote:
> On Wed, 4 Oct 2006, Qianqian Fang wrote:
>
>> By duplicating the http header captured by LiveHTTPHeader, now I can
>> submit files to wiki with the attached perl script. However, I found
>> there is a limitation, when submitting text files with size greater
>> than ~100k, the script returned with no error message, but no data
>> was posted.
>>
>> I don't know if this is related to the maximum length for sh command
>> line (I can not find the limit on the web), or it is curl's limit?
>> and if there is a way to get around?
>
> The exact command line limit depends on your particular shell, but it
> could very well be that limit you've hit. Try using "-d @file" or "-d
> @-" to read the data to post from a file or stdin to circumvent that
> limitation.
>
Received on 2006-10-04