#!/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"; } #### #!/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,PrintError => 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;