cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Re: post textarea field with the content from a text file

From: Qianqian Fang <fangq_at_nmr.mgh.harvard.edu>
Date: Thu, 21 Sep 2006 11:19:38 -0400

replacing all -F to -d generate similar result as all -F, i.e.
the file name was pasted as the field value instead of the
file content.

I wrote a perl script and tried to encode the content of
the file first and then insert into the -d/-F option, however,
it returned with no error message, nor did the uploading.

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://wenq.org/eindex.cgi";
}
open (FIN,"<$file") || die("can not open file $file");
@content=<FIN>;
close(FIN);

$text=&UrlEncode(join("",@content));
$oldtime=time;
system("curl -d 'text=$text' -d 'summary=$summary&oldtime=$oldtime&title=$title&Save=Save' '$url' > test.log");

sub UrlEncode {
  my $str = shift;
  return '' unless $str;
  my @letters = split(//, $str);
  my @safe = ('a' .. 'z', 'A' .. 'Z', '0' .. '9', '-', '_', '.',
       '!', '~', '*', '(', ')', '#','=','/',':');
  foreach my $letter (@letters) {
    my $pattern = quotemeta($letter);
    if (not grep(/$pattern/, @safe)) {
      $letter = sprintf("%%%02x", ord($letter));
    }
  }
  return join('', @letters);
}

-------------- 2006-09-21 02:29:22 you written: ------------

>On Wed, Sep 20, 2006 at 10:08:28PM -0400, Qianqian Fang wrote:
>> hi Dan
>>
>> I changed the command option from "-F text=@Redbird.f90" to
>> "-d text=@Redbird.f90", and got this error message:
>>
>> You can only select one HTTP request!
>>
>> does that mean I should put all request parameters into the content of
>> the file?
>
>You need to change all the -F to -d. Combining them doesn't make sense,
>so curl complains.
>
>>>> Dan
>--
>http://www.MoveAnnouncer.com The web change of address service
> Let webmasters know that your web site has moved
>
>

---------------------------------------------
Received on 2006-09-21