ashishg0310 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,.
Perl file
#!/usr/bin/perl use strict; use XML::Simple; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $server_endpoint = "http://localhost/cgi-bin/stackoverflow_ +in.cgi"; # set custom HTTP request header fields my $req = HTTP::Request->new(POST => $server_endpoint); $req->header('content-type' => 'application/json'); my $xml = XMLin('parsetest.xml',forcearray => 1); my $customer; foreach my $customer(@{$xml->{customer}}){ print "$customer->{first_name}->[0]\n"; print "$customer->{last_name}->[0]\n"; print "$customer->{dob}->[0]\n"; print "$customer->{email}->[0]\n"; } # add POST data to HTTP request body my $post_data1 = $customer->{first_name}->[0]; my $post_data2 = $customer->{last_name}->[0]; my $post_data3 = $customer->{dob}->[0]; my $post_data4 = $customer->{email}->[0]; $req->content($post_data1,$post_data2,$post_data3,$post_data4); my $resp = $ua->request($req); if ($resp->is_success) { my $message = $resp->decoded_content; print "Received reply: $message\n"; } else { print "HTTP POST error code: ", $resp->code, "\n"; print "HTTP POST error message: ", $resp->message, "\n"; }
CGI file
#!/usr/bin/perl # Title Processor.pl use CGI; use DBI; my $cgi = CGI->new; my $local = $cgi->param("POSTDATA"); print $cgi->header(-type => "application/json", -charset => "utf-8"); print "$local was received"; my $username = "test"; my $password = "test"; my $dsn = "dbi:mysql:detailsof:127.0.0.1"; my $dbh = DBI->connect($dsn,$username,$password,{RaiseError => 1,Print +Error => 0}) or die "cannot connect to database : $DBI::errstr"; my $sth = $dbh->prepare(qq{INSERT INTO cust_details.c_details(f_name,l +_name,dob_email) VALUES ('$customer->{first_name}->[0]','$customer->{ +last_name}->[0]','$customer->{dob}->[0]','$customer->{email}->[0]')}) +; $sth->execute() || die $DBI::errstr; $sth->finish(); $dbh->disconnect;
o/p: Received reply : was received.
i am not getting my parsed data which should be between reply and was.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: unable to pass data
by NetWallah (Canon) on May 21, 2014 at 23:34 UTC | |
|
Re: unable to pass data
by cord-bin (Friar) on May 22, 2014 at 14:45 UTC | |
|
Re: unable to pass data
by Anonymous Monk on May 22, 2014 at 06:08 UTC | |
|
Re: unable to pass data
by ashishg0310 (Novice) on May 22, 2014 at 03:47 UTC | |
by NetWallah (Canon) on May 22, 2014 at 05:37 UTC | |
|
Re: unable to pass data
by ashishg0310 (Novice) on May 22, 2014 at 18:26 UTC | |
by poj (Abbot) on May 22, 2014 at 19:46 UTC | |
|
Re: unable to pass data
by Anonymous Monk on Jun 04, 2014 at 07:38 UTC | |
|
Re: unable to pass data
by Anonymous Monk on Jun 03, 2014 at 08:36 UTC | |
by poj (Abbot) on Jun 03, 2014 at 10:49 UTC | |
|
Re: unable to pass data
by Anonymous Monk on Jun 03, 2014 at 19:28 UTC | |
by poj (Abbot) on Jun 03, 2014 at 19:54 UTC |