Open tobias-schleinkofer opened 11 years ago
use REST requests/responses to get/post data from/to the applications. Something like that should do the job:
#!/usr/bin/perl use strict; use warnings; use REST::Client; use Data::Dumper; use MIME::Base64; use JSON::XS; BEGIN { $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0 } # working GET use JSON; my $client = REST::Client->new(); #$client->addHeader("Authorization", "Basic " . encode_base64("foo:bar")); ##at rails controller: http_basic_authenticate_with :name => "foo", :password => "bar" $client->GET('https://localhost/trialregistry/trials.json'); my $response = from_json($client->responseContent()); my @a = @$response; foreach (@a) { my %h = %{$_}; foreach my $k (keys %h) { print $k . " => " . $h{$k} . "\n"; } } # working POST my $uri = 'https://localhost/trialregistry/hits'; my $json = '{"trial_id" : "2", "nurse_ou" : "BLA", "func_ou" : "BLUB", "ext_doc_id" : "M0815"}'; my $req = HTTP::Request->new('POST', $uri); $req->header( 'Content-Type' => 'application/json' ); $req->content($json); my $lwp = LWP::UserAgent->new; $lwp->request($req);
use REST requests/responses to get/post data from/to the applications. Something like that should do the job: