admin | 19 Nov 2009 12:52

Perl WWW::Curl::Easy equivalent of PHP's CURLOPT_RETURNTRANSFER

Hello, I couldn't find a Perl mailing list, so excuse me for asking here.

I really need to post some data, and get the response back. Just how 
would I do that? I currently have this:

$curl->setopt(CURLOPT_POSTFIELDS, $data);
$curl->setopt(CURLOPT_URL, 'https://example.com/path/to/script');
$curl->setopt(CURLOPT_VERBOSE, 1);
$curl->setopt(CURLOPT_POST, 1);
$curl->setopt(CURLOPT_SSLVERSION, 3);
$curl->perform();

There's no CURLOPT_RETURNTRANSFER in libcurl C API, and I presume Perl 
doesn't have it either. WWW::Curl has almost zero documentation. Thanks 
for any help.
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

Daniel Stenberg | 19 Nov 2009 13:37
Picon
Favicon
Gravatar

Re: Perl WWW::Curl::Easy equivalent of PHP's CURLOPT_RETURNTRANSFER

On Thu, 19 Nov 2009, admin <at> azuni.net wrote:

> Hello, I couldn't find a Perl mailing list, so excuse me for asking here.

CURLOPT_RETURNTRANSFER was invented by the PHP binding author and is basically 
just a shortcut for appending all received data into a memory buffer.

With the C API and basically all existing bindings as well (including the PHP 
one) you can use a write callback to append all data to a single buffer.

--

-- 

  / daniel.haxx.se
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

admin | 19 Nov 2009 15:32

Re: Perl WWW::Curl::Easy equivalent of PHP's CURLOPT_RETURNTRANSFER

Daniel Stenberg wrote:
> On Thu, 19 Nov 2009, admin <at> azuni.net wrote:
> 
>> Hello, I couldn't find a Perl mailing list, so excuse me for asking here.
> 
> CURLOPT_RETURNTRANSFER was invented by the PHP binding author and is 
> basically just a shortcut for appending all received data into a memory 
> buffer.
> 
> With the C API and basically all existing bindings as well (including 
> the PHP one) you can use a write callback to append all data to a single 
> buffer.
> 
 From the tutorial at http://curl.haxx.se/libcurl/c/libcurl-tutorial.html
I guess
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);
curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, write_data);

which in Perl would probably translate to
sub write_data($$$$) { ... }
$curl->setopt(CURLOPT_WRITEFUNCTION, \&write_data);

Can you please tell me how to use that? I know for sure that the 
resource that I POST to would only return one line of text as its 
response (0 or 1). How can I check for that? WWW::Curl seems to be a 
thin Perl wrapper around a .so library, so I don't have the source code 
to look at.
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

(Continue reading)

Daniel Stenberg | 19 Nov 2009 20:22
Picon
Favicon
Gravatar

Re: Perl WWW::Curl::Easy equivalent of PHP's CURLOPT_RETURNTRANSFER

On Thu, 19 Nov 2009, admin <at> azuni.net wrote:

>> With the C API and basically all existing bindings as well (including the 
>> PHP one) you can use a write callback to append all data to a single 
>> buffer.
>> 
> From the tutorial at http://curl.haxx.se/libcurl/c/libcurl-tutorial.html
> I guess
> size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);
> curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, write_data);

Exactly. And CURLOPT_WRITEDATA to set the custom pointer passed to the 
callback.

> which in Perl would probably translate to
> sub write_data($$$$) { ... }
> $curl->setopt(CURLOPT_WRITEFUNCTION, \&write_data);
>
> Can you please tell me how to use that?

Well, I'm not a user of the perl binding but I looked at their package and it 
is strange that I can find them but you obviously can't:

http://cpansearch.perl.org/src/SZBALINT/WWW-Curl-4.09/t/02callbacks.t

> How can I check for that? WWW::Curl seems to be a thin Perl wrapper around a 
> .so library, so I don't have the source code to look at.

Both WWW::Curl and libcurl are 100% open source with source code available, 
you can indeed get the source to look at. If you want to.
(Continue reading)

admin | 20 Nov 2009 08:52

Re: Perl WWW::Curl::Easy equivalent of PHP's CURLOPT_RETURNTRANSFER

Daniel Stenberg wrote:

>> Can you please tell me how to use that?
> 
> Well, I'm not a user of the perl binding but I looked at their package 
> and it is strange that I can find them but you obviously can't:
> 
> http://cpansearch.perl.org/src/SZBALINT/WWW-Curl-4.09/t/02callbacks.t
> 
Thanks! Unit tests, coupled with official documentation, once again 
prove to be the best howto on how to use the thing:

		my $response;
                 sub write_data($$$$) {
                         $response = shift;
                         return length($response);
                 }
                 $curl->setopt(CURLOPT_POSTFIELDS, $data);
                 $curl->setopt(CURLOPT_URL, 
'https://example.com/path/to/script');
                 $curl->setopt(CURLOPT_VERBOSE, 1);
                 $curl->setopt(CURLOPT_POST, 1);
                 $curl->setopt(CURLOPT_SSLVERSION, 3);
                 $curl->setopt(CURLOPT_SSL_VERIFYPEER, 0);
                 $curl->setopt(CURLOPT_HEADER, 0);
                 $curl->setopt(CURLOPT_WRITEFUNCTION, \&write_data);
                 $curl->perform();
                 print STDERR "got response: '$response'\n";

Working like a charm without using any CURLOPT_WRITEDATA.
(Continue reading)

muratori | 28 Nov 2009 16:45
Picon

Curl error 35 from NUSOAP and Curl command line

Hi,

I recently updated a test-web server to Opensuse 11.0, php 5.2.11 and  
curl  7.18.1. I get this error from php (NUSOAP): (url omitted for  
some security reason).

HTTP Error: cURL ERROR: 35: error:140773F2:SSL  
routines:SSL23_GET_SERVER_HELLO:sslv3 alert unexpected message
url: https:...

I've tried to have a verbose response from command line curl with: curl -v
and I received (url and IP omitted for security reason):

  Connected to ****** (****) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
   CApath: /etc/ssl/certs/
* SSLv3, TLS handshake, Client hello (1):
* error:140773F2:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert  
unexpected message
* Closing connection #0
curl: (35) error:140773F2:SSL routines:SSL23_GET_SERVER_HELLO:sslv3  
alert unexpected message

I previously used my php scripts and curl without any problem. Has  
anybody idea?

Thanks,
Vic

(Continue reading)


Gmane