0
我的下一段代碼替換反斜槓
sub raw_query {
my ($self,%args) = @_;
state $global_id = int(rand(10000));
$args{'jsonrpc'} = '2.0';
if ($self->cookie) { $args{'auth'} = $self->cookie; }
$args{'id'} = $global_id++;
if ($self->{verbosity} == 1) {
print Dumper(\%args);
}
%args=quotemeta %args;
for (my $i=0; $i< $self->{retries}; $i++){
my $response = eval { $self->{ua}->post($self->{server},
'Content-Type' => 'application/json-rpc',
'Content' => JSON->new->escape_slash->utf8->encode(\%args)) };
返回我回斜線一些值,從而JSON編碼失敗:
\{
'main' => '1',
'hostid' => '1',
'useip' => '1',
'type' => '2',
'bulk' => '1',
'interfaceid' => '1',
'ip' => '1.2.8.4',
'port' => '1',
'dns' => 'test'
}
能否請你幫替換此backslah:從\ {到{?
'%args = quotemeta%args'是非常錯誤的,你會看到警告'散列分配中奇數個元素。請不要忽視警告。目標並不明顯,但由於您無法直接修改哈希鍵,我猜測您可能想要在哈希*值*中轉義非單詞字符。這就像'$ _ = quotemeta值%args'一樣。但是你確定你想要HTTP消息體中的轉義字符嗎? – Borodin
您是如何生成該輸出的?你應該在你的問題中顯示產生它的代碼。 – Borodin