Ok, got it :- 1. get the content-parts: $tx->req->content->parts; 2. by checking each parts body_contains method identify them 3. build a new parts array with correct sequence by copying the objects into a new array. 4. change the whole thing: $tx->req->content->parts($sorted_parts);
This request eventually saves the backup as I want it :-) You might ask if it is really worth it but I learned quite a lot debugging this problem And there is a wish: please allow adding form parameters as an array. After all they end up in an array eventually (parts is an array_ref). It is a pitty that the sequence is just determined by a sort on the names i.e. arbitrarily. In most cases it doesn't matter but if it does this saves a lot of fuzz. -Michael Am Mittwoch, 13. Mai 2020 23:56:26 UTC+2 schrieb Michael Lackhoff: > > 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/99009410-9157-443e-ad36-879418436310%40googlegroups.com.