Please show us the code leading up to and including where you're calling the LWP::Curl code that triggers this error.
As far as the open call, it says: open a lexical file handle ($fileb) in write mode (>) to the file name that's located in $content. In this case, $content isn't a file name, it's a regular scalar, and by passing the reference to it treats it as an in-memory file, instead of an on-disk one.
| [reply] [d/l] [select] |
use LWP::Curl;
use Net::Curl::Easy qw(:constants);
my $lwpcurl = LWP::Curl->new();
my $referer = 'http://server.com/:5555';
my $post_url = 'http://userid:password@server.com:5555/receive';
open(my $fh, "<", "test.xml");
$lwpcurl->{agent}->setopt( CURLOPT_READDATA, $fh );
$lwpcurl->{agent}->setopt( CURLOPT_HEADERDATA, ['Content-Type:text/xml
+'] );
my $content = $lwpcurl->post($post_url, {}, $referer);
| [reply] [d/l] |
First, this *is* your code, and you're not checking whether the file opened successfully for read. Second, why are you breaking encapsulation by modifying the innards of the object?
Also, where are you getting the examples for calling setopt()? Everything I've found takes a reference, which you're not passing in.
Here's an example from Net::Curl::Easy:
$self->setopt( CURLOPT_FILE, \$self->{body} );
$self->setopt( CURLOPT_HEADERDATA, \$self->{head} );
I don't see any direct use examples for CURLOPT_READDATA.
I'm not in a position to test at the moment, so this is just a very wild guess, but first, ensure you handle opens correctly, then try the code as-is. If it still fails, try changing $lwpcurl->{agent}->setopt( CURLOPT_READDATA, $fh ); to $lwpcurl->{agent}->setopt( CURLOPT_FILE, $fh );. If that still doesn't work, try <c>$lwpcurl->{agent}->setopt( CURLOPT_FILE, \$fh );. All that said, I really, really don't think that modifying the agent like that was intended by the developers (I could be wrong though).
Can you please post a link to where you're taking your examples from, or what you're basing your code on? | [reply] [d/l] [select] |
The error is because you are not testing your open.
When opening a file, it's seldom a good idea to continue if the request failed, so open is frequently used with die. Even if die won't do what you want (say, in a CGI script, where you want to format a suitable error message (but there are modules that can help with that problem)) always check the return value from opening a file.
Changing line 234 to open( my $fileb, ">", \$content ) or die "$!";
should be informative.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
| [reply] [d/l] |
| [reply] [d/l] |
as perhaps corrupt/lack of memory or other oddness can still prevent the open. :) if it failed, wouldn't writing to the filehandle fail also?
| [reply] |
The open() you refer to is not in my code, it's in the perl module. I agree the success/failure of the open() should be tested.
| [reply] [d/l] [select] |
$lwpcurl->{agent}->setopt( CURLOPT_HEADERDATA, ['Content-Type:text/xml
+'] );
The error:
Can't use an undefined value as filehandle reference at /home/mware/httppost/lib/perl5/site_perl/5.8.8/LWP/Curl.pm line 236.
Goes away.
Although, the http post still does not work properly. I'm not seeing my test file on the server. I have a curl command line test that works correctly, but can not seem to configure the perl code to do the same. | [reply] [d/l] |