###PERL_LIB: use lib '/botm/lib/post';
use botm_common (
- 'read_data_file', 'write_data_file',
+ 'read_data_file', 'write_data_file', 'write_postdata_file',
+ 'read_header_file',
'merge_url',
'make_temp_path',
'system_encoded'
my $cookie_path = make_temp_path(TMP_PATH, 'sendpost.cookie.txt');
my $postdata_path = make_temp_path(TMP_PATH, 'sendpost.postdata.txt');
- wget($post_url, $tmp_path);
-
+ my %wget_options = (
+ 'with_header', 1,
+ 'cookie_path', $cookie_path,
+ 'postdata_path', $postdata_path
+ );
+ my %post_data = (
+ 'uvwxyz', 'eół',
+ 'lel', 'lol'
+ );
+
+ wget($post_url, $tmp_path, \%wget_options, \%post_data);
+
+ # unlink($tmp_path, $cookie_path, $postdata_path);
}
sub wget {
- (my $url, my $path, my $postdata) = @_;
+ (my $url, my $path, my $options, my $postdata) = @_;
+
+ my @arg = (
+ WGET,
+ '-q'
+ );
+
+ if ($options->{'with_header'}) {
+ push(@arg, '--save-headers');
+ }
+
+ if ($options->{'cookie_path'} ne '') {
+ if (-f $options->{'cookie_path'}) {
+ push(@arg, '--load-cookies='.$options->{'cookie_path'});
+ }
+ push(@arg, '--save-cookies='.$options->{'cookie_path'});
+ }
+ else {
+ push(@arg, '--no-cookies');
+ }
+
+ if ($options->{'postdata_path'} ne '') {
+ if (defined $postdata) {
+ write_postdata_file(
+ $options->{'postdata_path'},
+ ENCODING_FILE, '',
+ $postdata
+ );
+ push(@arg, '--post-file='.$options->{'postdata_path'});
+ }
+ }
+
+ push(@arg, (
+ $url,
+ '-O', $path
+ ));
+
- my @arg = (WGET, '-q', $url, '-O', $path);
system_encoded(WGET, @arg);
return 1;
}
+