Json 使用REST::Client发布请求
我正在使用REST::Client创建POST请求,并不断收到以下错误: 响应:在/nethome/perl5/lib/perl5//LWP/Protocol/http.pm第254行第1行不是标量引用 我的代码片段:Json 使用REST::Client发布请求,json,rest-client,Json,Rest Client,我正在使用REST::Client创建POST请求,并不断收到以下错误: 响应:在/nethome/perl5/lib/perl5//LWP/Protocol/http.pm第254行第1行不是标量引用 我的代码片段: use warnings; use diagnostics; use strict; use JSON::MaybeXS; use REST::Client; my $host = 'myurl'; my $hashref = {}; my $jsonEncode=JSON
use warnings;
use diagnostics;
use strict;
use JSON::MaybeXS;
use REST::Client;
my $host = 'myurl';
my $hashref = {};
my $jsonEncode=JSON::MaybeXS->new->utf8(1)->pretty(1);
在子例程内部,使用while循环
my @fields=split("\t",$_);
my $sample_id=$fields[0];
my $chr=$fields[1];
my $position=$fields[2];
my $alt=$fields[5];
my $hashref =("variant_request"=>{"searchParameters"=>{"sampleIds"=> ["$sample_id"],"genome"=>[{"loci"=>{"chromosome"=>"$chr","position"=>$position,"allele"=>"$alt"}}]}});
push (@meta,\%hashref);
printQuery (@meta,$encoded);
内部PrintQuery子例程:
my $filename =$_[1];
my $hash = $jsonEncode->canonical->encode($_[0]);
$client->POST($hash,{'Content-Type'=>'application/json','Accept'=>'application/json'});
print 'Response:'.$client->responseContent()."\n";
print 'Response Status:'. $client->responseCode()."\n";
输入:
601 1 114872280 rs544699256 A G
所以我不太清楚为什么会这样: 更改为:
my $client=REST::Client->new(host=>$host);
致:
增加:
my $url = 'myurl';
最后改变了:
$client->POST($url,$jsonrequest,{'Content-Type'=>'application/json','Accept'=>'application/json'});
$client->POST($url,$jsonrequest,{'Content-Type'=>'application/json','Accept'=>'application/json'});