cURL / Mailing Lists / curl-users / Single Mail

curl-users

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

From: Qianqian Fang <fangq_at_nmr.mgh.harvard.edu>
Date: Wed, 04 Oct 2006 16:31:36 -0400

hi Dan

sorry for my late in replying. I haven't got chance to work on this
problem until today.

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?

thank you

Qianqian

by the way, the html page I am filling in is
http://wenq.org/eindex.cgi?action=edit&id=test

#!/usr/bin/perl
# usage: wikiin text_file_name wiki_page_name "change summary"

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=&UrlEncode2(join("",@content));

$oldtime=time;

system("curl -d 'oldtime=$oldtime' -d 'title=$title' -d
'summary=$summary' -d 'Save=Save' -d 'text=$text' '$url'");

sub UrlEncode2 {
  my $str = shift;
  return '' unless $str;
  my @letters = split(//, $str);
  my @unsafe = ('\'','&','+','?',';');
  foreach my $letter (@letters) {
    my $pattern = quotemeta($letter);
    if (grep(/$pattern/, @unsafe)) {
      $letter = sprintf("%%%02X", ord($letter));
    }
  }
  return join('', @letters);
}

Daniel Stenberg wrote:
> On Thu, 21 Sep 2006, Qianqian Fang wrote:
>
>> 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.
>
> 1. Always always always use LiveHTTPHeader first when doing the operation
> manually and then try to repeat the same request with curl
>
> And if that doesn't work for you:
>
> 2. Show us the HTML of the form you want curl to "fill in", and
> possibly even
> some request/response headers from (1)
>
Received on 2006-10-04