mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-04 05:16:45 +00:00
HttpUtils: "POST data as hash" patch from justme1968
git-svn-id: https://svn.fhem.de/fhem/trunk@4909 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
353719c207
commit
c925a10616
@ -171,19 +171,31 @@ HttpUtils_Connect2($)
|
|||||||
return "$hash->{displayurl}: Can't connect to $hash->{addr}: $@";
|
return "$hash->{displayurl}: Can't connect to $hash->{addr}: $@";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $data;
|
||||||
|
if(defined($hash->{data})) {
|
||||||
|
if( ref($hash->{data}) eq 'HASH' ) {
|
||||||
|
foreach my $key (keys %{$hash->{data}}) {
|
||||||
|
$data .= "&" if( $data );
|
||||||
|
$data .= "$key=". urlEncode($hash->{data}{$key});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$data = $hash->{data};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$hash->{host} =~ s/:.*//;
|
$hash->{host} =~ s/:.*//;
|
||||||
my $hdr = ($hash->{data} ? "POST" : "GET")." $hash->{path} HTTP/1.0\r\n";
|
my $hdr = ($data ? "POST" : "GET")." $hash->{path} HTTP/1.0\r\n";
|
||||||
$hdr .= "Host: $hash->{host}\r\n";
|
$hdr .= "Host: $hash->{host}\r\n";
|
||||||
$hdr .= "Authorization: Basic $hash->{auth}\r\n" if(defined($hash->{auth}));
|
$hdr .= "Authorization: Basic $hash->{auth}\r\n" if(defined($hash->{auth}));
|
||||||
$hdr .= $hash->{header}."\r\n" if(defined($hash->{header}));
|
$hdr .= $hash->{header}."\r\n" if(defined($hash->{header}));
|
||||||
if(defined($hash->{data})) {
|
if(defined($data)) {
|
||||||
$hdr .= "Content-Length: ".length($hash->{data})."\r\n";
|
$hdr .= "Content-Length: ".length($data)."\r\n";
|
||||||
$hdr .= "Content-Type: application/x-www-form-urlencoded\r\n"
|
$hdr .= "Content-Type: application/x-www-form-urlencoded\r\n"
|
||||||
if ($hdr !~ "Content-Type:");
|
if ($hdr !~ "Content-Type:");
|
||||||
}
|
}
|
||||||
$hdr .= "\r\n";
|
$hdr .= "\r\n";
|
||||||
syswrite $hash->{conn}, $hdr;
|
syswrite $hash->{conn}, $hdr;
|
||||||
syswrite $hash->{conn}, $hash->{data} if(defined($hash->{data}));
|
syswrite $hash->{conn}, $data if(defined($data));
|
||||||
shutdown $hash->{conn}, 1 if(!$hash->{noshutdown});
|
shutdown $hash->{conn}, 1 if(!$hash->{noshutdown});
|
||||||
|
|
||||||
if($hash->{callback}) { # Nonblocking read
|
if($hash->{callback}) { # Nonblocking read
|
||||||
|
Loading…
x
Reference in New Issue
Block a user