curl-library
Re: Re: Curl::easy / Authorize.net
Date: Thu, 17 Apr 2003 19:29:39 -0500 (GMT)
Thanks for your help, although it turns out that the problem was in a variable required by authorize.net that I could find nowhere in their docs. Only after bugging them did I get to the bottom of it. However, now I'm at the next step. I need to capture their response as a string (then turn it into an array) and do stuff with it. I have appropriated part of the body callback from the /t folder, but haven't got it to work yet. The relevant part is below:
open BODY, ">body.out";
$curl->setopt(CURLOPT_FILE,*BODY);
my $body_called=0;
my $chunk;
my $auth_response;
sub body_callback {
my ($chunk,$handle)=@_;
print STDERR "body callback called with ",length($chunk)," bytes\n";
print STDERR "data=$chunk\n";
$body_called++;
return length($chunk); # OK
}
# test for ref to sub and body callback
my $body_ref=\&body_callback;
$curl->setopt(CURLOPT_WRITEFUNCTION, $body_ref);
my $err_response = "";
$auth_response = $body_ref;
if ($curl->perform() != 0) {
$err_response = "There has been an error.";
};
print "Content-type: text/html\n\n";
print "<html><body>\n";
print "<hr>Transaction Results!<br><hr>\n";
print "BODY REF: $body_ref<br><hr>\n";
print "ERROR? $err_response<br>\n";
print "AUTH RESPONSE: $auth_response<br><hr>\n";;
print "</body></html>\n";
As you might be able to tell, I'm trying to get the response into the var. $auth_response, but that is not what I get. With the above code, from the command line, this is what I get:
body callback called with 23 bytes
data=HTTP/1.1 100 Continue
body callback called with 27 bytes
data=Server: Microsoft-IIS/5.0
body callback called with 37 bytes
data=Date: Fri, 18 Apr 2003 02:16:50 GMT
body callback called with 2 bytes
data=
body callback called with 17 bytes
data=HTTP/1.1 200 OK
body callback called with 27 bytes
data=Server: Microsoft-IIS/5.0
body callback called with 37 bytes
data=Date: Fri, 18 Apr 2003 02:16:50 GMT
body callback called with 19 bytes
data=Connection: close
body callback called with 25 bytes
data=Content-Type: text/html
body callback called with 21 bytes
data=Content-Length: 301
body callback called with 2 bytes
data=
body callback called with 201 bytes
##this is the part I want to keep##
data=|1|,|1|,|1|,|This transaction has been approved.|,|000000|,|P|,|0|,||,||,|120.50|,|CC|,|auth_capture|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|839B05D8102FAB9C90EF159
##end important part##
body callback called with 100 bytes
##this below seems to be a continuation of the above chunk,##
##but relatively unimportant to me##
data=DCDF0856E|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||
Content-type: text/html
<html><body>
<hr>Transaction Results!<br><hr>
BODY REF: CODE(0x81c7a34)<br><hr>
ERROR? <br>
AUTH RESPONSE: DCDF0856E|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||<br><hr>
</body></html>
As you can see, the real information is in that |x|,|x|,|x|... part. How can I get that in a usable form?
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-04-18