使用REST :: Client发出POST请求

时间:2015-12-22 20:38:31

标签: json rest-client

我正在使用REST :: Client创建一个POST请求并继续收到以下错误:

响应:不是/althome/perl5/lib/perl5//LWP/Protocol/http.pm第254行的SCALAR参考,< IFH>第1行。

我的代码片段:

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 

1 个答案:

答案 0 :(得分:0)

所以不确定为什么会这样: 改变了这个:

my $client=REST::Client->new(host=>$host);

要:

my $client=REST::Client->new();

添加了:

my $url = 'myurl';

最后改变了:

$client->POST($url,$jsonrequest,{'Content-Type'=>'application/json','Accept'=>'application/json'});