bbarodia has asked for the wisdom of the Perl Monks concerning the following question:

Hi , I am trying to interface witha a server which accepts multipart/mixed content type.I am using REST::client to send a post request and the content is created using the MIME::Entity module. However when i try to post , I am getting a 500 Not a scalar reference error. Not sure how to post with a scalar variable. my code :
sub uploadCodeCoverageZip { # Verify everything and if it checks out call the WSDL. Otherwise just + return error my $self = shift(); my $ret = "Unknown Error\n"; # get an xml from xml::simple my $ws_request = createCodeCoverageObject( password => $self->{password}, coverageType => $self->{coverageType}, buildVersion => $self->{buildVersion}, testPlanId => $self->{testPlanId}, loginId => $self->{loginId}, cloverFilePath => $self->{cloverFilePat +h}, ); my $multipart = MIME::Entity->build(Type => "multipart/mix +ed"); # this might work but gives a Not a scalar reference when used + as request content my $url = 'http://someserver.com/path/to/ws'; '#'my server my $ua = LWP::UserAgent->new; my $h = HTTP::Headers->new; my $file = '/etc/passwd'; # Name the file open(INFO, $file); # Open the file my @lines = <INFO>; # Read it into an array close(INFO); $h->header('Content-Type' => 'multipart/mixed', Accept=>'appli +cation/json','Cookie', $by->{cookie},'User-Agent', $self->getUserAgen +t()); my @ws_result_array = (); # approximating the post request push (@ws_result_array, '--Boundary'); push (@ws_result_array, $ws_request); push (@ws_result_array, '--Boundary'); push (@ws_result_array, @lines); my $GetReq = HTTP::Request->new( 'POST', $url, $h, @ws_result_array // not sure what to put here ); print $GetReq->as_string; my $resp = $ua->request($GetReq); print $resp->decoded_content; return "eod"; }
the above code returns a request syntactically incorrect response from server I have tried attaching objects to the multipart object but that gives a not a scalar reference error. do let me know if you need nething thnx help is much appreciated. thanks

Replies are listed 'Best First'.
Re: perl client with multipart/mixed content
by Anonymous Monk on Jul 29, 2011 at 00:07 UTC
    Please provide some code, treduced to a minimum that compiles and still produces the error.

      sub uploadCodeCoverageZip { # Verify everything and if it checks out call the WSDL. Otherwise just + return error my $self = shift(); my $ret = "Unknown Error\n"; # get an xml from xml::simple my $ws_request = createCodeCoverageObject( password => $self->{password}, coverageType => $self->{coverageType}, buildVersion => $self->{buildVersion}, testPlanId => $self->{testPlanId}, loginId => $self->{loginId}, cloverFilePath => $self->{cloverFilePat +h}, ); my $multipart = MIME::Entity->build(Type => "multipart/mix +ed"); # this might work but gives a Not a scalar reference when used + as request content my $url = 'http://someserver.com/path/to/ws'; '#'my server my $ua = LWP::UserAgent->new; my $h = HTTP::Headers->new; my $file = '/etc/passwd'; # Name the file open(INFO, $file); # Open the file my @lines = <INFO>; # Read it into an array close(INFO); $h->header('Content-Type' => 'multipart/mixed', Accept=>'appli +cation/json','Cookie', $by->{cookie},'User-Agent', $self->getUserAgen +t()); my @ws_result_array = (); # approximating the post request push (@ws_result_array, '--Boundary'); push (@ws_result_array, $ws_request); push (@ws_result_array, '--Boundary'); push (@ws_result_array, @lines); my $GetReq = HTTP::Request->new( 'POST', $url, $h, @ws_result_array // not sure what to put here ); print $GetReq->as_string; my $resp = $ua->request($GetReq); print $resp->decoded_content; return "eod"; }
      the above code returns a request syntactically incorrect response from server I have tried attaching objects to the multipart object but that gives a not a scalar reference error. do let me know if you need nething thnx
        Was there ever an answer to this question? I'm doing the same thing, using REST::Client and MIME::Entity, and I'm getting back "Not a SCALAR reference". Is there solution to do the REST post in the correct fashion?