[Mojolicious] Re: curl works, Mojo::UserAgent doesn't

2020-05-13 Thread Scott Wiersdorf
It's possible the `-k` option to curl is the difference. The equivalent in 
Mojo::UserAgent is `$ua->insecure(1)` (which you can chain off of).

Scott

On Wednesday, May 13, 2020 at 3:56:26 PM UTC-6, Michael Lackhoff wrote:
>
> I had quite a bit of success recently using Mojo::UserAgent so I tried to 
> replace a curl command to do a backup of my Fritz.box router with M::U.
>
> Here is the curl command:
> curl -s -k -o $OUT --form sid=$SID --form ImportExportPassword=$BAKPWD \
> --form ConfigExport= http://fritz.box/cgi-bin/firmwarecfg
>
> It should be equivalent to this M::U request:
>
> my $tx = $ua->build_tx(
> POST => 'http://fritz.box/cgi-bin/firmwarecfg' =>
> {
> 'Accept'   => '*/*',
> 'Content-Type' => 'multipart/form-data',
> } => form => {
> sid  => $SID,
> ImportExportPassword => $BAKPWD,
> ConfigExport => '',
> }
> );
>
> # for debugging:
> print $tx->req->to_string;
>
> $tx = $ua->start($tx);
> $tx->res->save_to($OUT);
>
> As far as I can tell both the headers and the POST body is very much the 
> same (except the boundary value to separate the form fields) but to my 
> surprise the curl command works ($OUT is the backup file) but with the M::U 
> version $OUT consists of some HTML output indicating an error.
>
> If I could see a difference I could try to better adjust my script but as 
> I said, they look very much the same (I compared it with the -v and 
> --trace-ascii output of curl), so I run out of ideas what could trigger the 
> differnt response of my Fritz.box.
> Any ideas? At the moment I just solve it by using the curl command with 
> "system" but I would prefer a Perl-only solution and what is even more 
> important to me: I want to understand what is going on here.
>
> -Michael
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/61ee3b8a-ca87-424d-91e1-f807001afa37%40googlegroups.com.


Re: [Mojolicious] curl works, Mojo::UserAgent doesn't

2020-05-13 Thread Stefan Adams
I'm certain you'll be able to accomplish this with M::UA. Can you share
what the HTML error produced is?

Can you share the output that you are comparing that you are noticing is so
similar between curl and M::UA? You're using -v for curl. Also set the
MOJO_CLIENT_DEBUG env variable to 1.

See how it works comparing curl to:

   $ env MOJO_CLIENT_DEBUG=1 mojo get -v -M POST -f sid=$SID -f
ImportExportPassword=$BAKPWD -f ConfigExport= http
://fritz.box/cgi-bin/firmwarecfg 

On Wed, May 13, 2020, 4:56 PM 'Michael Lackhoff' via Mojolicious <
mojolicious@googlegroups.com> wrote:

> I had quite a bit of success recently using Mojo::UserAgent so I tried to
> replace a curl command to do a backup of my Fritz.box router with M::U.
>
> Here is the curl command:
> curl -s -k -o $OUT --form sid=$SID --form ImportExportPassword=$BAKPWD \
> --form ConfigExport= http://fritz.box/cgi-bin/firmwarecfg
>
> It should be equivalent to this M::U request:
>
> my $tx = $ua->build_tx(
> POST => 'http://fritz.box/cgi-bin/firmwarecfg' =>
> {
> 'Accept'   => '*/*',
> 'Content-Type' => 'multipart/form-data',
> } => form => {
> sid  => $SID,
> ImportExportPassword => $BAKPWD,
> ConfigExport => '',
> }
> );
>
> # for debugging:
> print $tx->req->to_string;
>
> $tx = $ua->start($tx);
> $tx->res->save_to($OUT);
>
> As far as I can tell both the headers and the POST body is very much the
> same (except the boundary value to separate the form fields) but to my
> surprise the curl command works ($OUT is the backup file) but with the M::U
> version $OUT consists of some HTML output indicating an error.
>
> If I could see a difference I could try to better adjust my script but as
> I said, they look very much the same (I compared it with the -v and
> --trace-ascii output of curl), so I run out of ideas what could trigger the
> differnt response of my Fritz.box.
> Any ideas? At the moment I just solve it by using the curl command with
> "system" but I would prefer a Perl-only solution and what is even more
> important to me: I want to understand what is going on here.
>
> -Michael
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/14df452c-e7a4-4b7c-90a2-9e1f5e15becc%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CACyQ%2BFR1F7fqH3%3DFJCMftHuwH1rEKwyPZ%2BO0g7d%3DJcRaWYqDtw%40mail.gmail.com.


[Mojolicious] curl works, Mojo::UserAgent doesn't

2020-05-13 Thread 'Michael Lackhoff' via Mojolicious
I had quite a bit of success recently using Mojo::UserAgent so I tried to 
replace a curl command to do a backup of my Fritz.box router with M::U.

Here is the curl command:
curl -s -k -o $OUT --form sid=$SID --form ImportExportPassword=$BAKPWD \
--form ConfigExport= http://fritz.box/cgi-bin/firmwarecfg

It should be equivalent to this M::U request:

my $tx = $ua->build_tx(
POST => 'http://fritz.box/cgi-bin/firmwarecfg' =>
{
'Accept'   => '*/*',
'Content-Type' => 'multipart/form-data',
} => form => {
sid  => $SID,
ImportExportPassword => $BAKPWD,
ConfigExport => '',
}
);

# for debugging:
print $tx->req->to_string;

$tx = $ua->start($tx);
$tx->res->save_to($OUT);

As far as I can tell both the headers and the POST body is very much the 
same (except the boundary value to separate the form fields) but to my 
surprise the curl command works ($OUT is the backup file) but with the M::U 
version $OUT consists of some HTML output indicating an error.

If I could see a difference I could try to better adjust my script but as I 
said, they look very much the same (I compared it with the -v and 
--trace-ascii output of curl), so I run out of ideas what could trigger the 
differnt response of my Fritz.box.
Any ideas? At the moment I just solve it by using the curl command with 
"system" but I would prefer a Perl-only solution and what is even more 
important to me: I want to understand what is going on here.

-Michael

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/14df452c-e7a4-4b7c-90a2-9e1f5e15becc%40googlegroups.com.