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.

In reply to unable to pass data by ashishg0310

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.