cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Reading url request from a file ?

From: Javier Barroso <javibarroso_at_gmail.com>
Date: Sat, 4 Feb 2012 16:07:45 +0100

On Thu, Feb 2, 2012 at 3:14 PM, Javier Barroso <javibarroso_at_gmail.com> wrote:
> Hi,
>
> I would like to use curl but reading headers which I send from a file
> such http://pastebin.com/TcP0UVbd
>
> I'm thiniking in shell scripting (perl, awk ..), but maybe there is
> another easy method to do it
>
> I would like something like curl --read-request-from-file myfile
>
> I didn't find any like it in internet, but probabbly someone though
> in that before
>
> Do you have any idea or  I need to write an bash function which
> convert headers to -H curl switch , and use $() bash operator (and add
> data post which is included in the file too)?
Well, finally I did a perl script,sharing here:

#!/usr/bin/perl -w
use strict;

my %headers;
open my $tmpfile, ">tmpfile";
while (<>)
{
        if (1 .. /^$/)
        {
                chomp;
                next if (/^$/);
        
                my ($header,$value)=split (": ");
                
                $headers{$header}=$value;
        }
        else
        {
                print $tmpfile "$_";
        }
}
my ($url,$host)=@headers{qw(Post Host)};
delete @headers{qw(Post Host)};
my $command = "curl";
$command.=" -H \"$_: $headers{$_}\"" foreach keys %headers;
$command.=" -d \@tmpfile $host$url";
system $command;
unlink "tmpfile";

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-02-04