2015-12-22 3 views
0

Je crée une requête POST en utilisant REST :: Client et continue à obtenir l'erreur suivante:requête POST avec REST :: client

Réponse: Non une référence SCALAIRE à/nethome/perl5/lib/perl5 // LWP/Protocole/http.pm ligne 254, < PFSI> ligne 1.

Mon code Snippet:

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); 

l'intérieur d'un sous-programme, en utilisant en boucle

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); 

intérieur PrintQuery Sous-programme:

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"; 

Entrée:

601  1  114872280  rs544699256  A  G 

Répondre

0

donc pas exactement pourquoi cela a fonctionné: Changé Ce:

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

Pour:

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

Ajouté:

my $url = 'myurl'; 

Enfin changé:

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