homepage Welcome to WebmasterWorld Guest from 54.163.91.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
cURL response code
Not showing the correct http response
tekomp




msg:1283745
 9:03 pm on Apr 11, 2006 (gmt 0)

I have a php script connecting to a payment gateway through cURL and my response handling isn't working as expected. The http response being returned from the gateway is 699, but CURLINFO_HTTP_CODE is showing 200. Here's the relevant code:


$res = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$resp = explode("\n\r\n", $res);
$header = explode("\n", $resp[0]);

echo "<pre>";
echo "HTTP Code: " . $httpCode . "<br />";
print_r($header);
echo "</pre>";

Here's the output:

HTTP Code: 200
Array
(
[0] => HTTP/1.0 699 20111: Missing card or check number
[1] => Connection: close
[2] => Content-Type: text/plain
[3] => Content-Length: 0
)

As you can see from the actual header, the code is 699, but cURL is claiming it's 200. Any ideas what this may be?

 

vacorama




msg:1283746
 4:47 pm on Apr 12, 2006 (gmt 0)

i'm not sure but i don't think there is a 699 http code, i thought they stop at 505... it seems to be an error code used by gateway. if you got a response from the server with details about your request, a 200 code would make sense, meaning everything went fine.

tekomp




msg:1283747
 5:17 pm on Apr 12, 2006 (gmt 0)

The gateway uses HTTP codes in the 600's to indicate input errors. It will return a 200 on a proper transaction though.

Any ideas?

jatar_k




msg:1283748
 5:33 pm on Apr 12, 2006 (gmt 0)

I think the error is coming from them as you said

"Missing card or check number "

doesn't have anything to do with the http of the whole thing, it is an error they are returning based on the data you sent

just a guess but the 200 http code is correct, the data you are transmitting is wrong

tekomp




msg:1283749
 5:55 pm on Apr 12, 2006 (gmt 0)

Hi all,

I appreciate the help. I know that my input is incorrect, I'm actually trying to code the error handling portion so I want to receive errors from the gateway. The way the gateway's API handles errors, is it returns various HTTP codes along with the header to indicate the reason for the error. For example, take a look at this header viewer site that shows the gateways header response:

header viewer [web-sniffer.net]

From the gateway docs: "Exception are reported as HTTP errors". Here is the API documentation on exception reporting: Exception reporting [netbilling.com]

Anybody?

vacorama




msg:1283750
 6:11 pm on Apr 12, 2006 (gmt 0)

ahh i see... it sounds like it must have something to do with the way curl is grabbing the http code. if they are using http codes as a means of exception reporting, then maybe using fsockopen() and manually sending the request will show you whether curl is causing the problem or not... if it is, maybe some curl config stuff can fix...

tekomp




msg:1283751
 8:25 pm on Apr 12, 2006 (gmt 0)

ahh i see... it sounds like it must have something to do with the way curl is grabbing the http code. if they are using http codes as a means of exception reporting, then maybe using fsockopen() and manually sending the request will show you whether curl is causing the problem or not... if it is, maybe some curl config stuff can fix...

Well here is the output of using fsockopen:

HTTP/1.0 604 Missing Parameter (pay_type) Connection: close Content-Type: text/plain Content-Length: 0

The http code coming back is definately not 200. I'm stumped.

vacorama




msg:1283752
 9:00 pm on Apr 12, 2006 (gmt 0)

that's really weird. so with both curl and fsockopen you are sending the same exact info and getting two different response codes? of the two methods, which response code is more appropriate to the info you are sending the 699 or the 604? if it's 604, then it starting to look like curl is failing somewhere, since it would be outputting two wrong codes (200 and 699)...

tekomp




msg:1283753
 9:31 pm on Apr 12, 2006 (gmt 0)

Well I feel like an idiot. In a snippet I didn't put in this post:

if($httpCode == "200") {
if($primaryResult['status_code'] == '1' $primaryResult['status_code'] == "I") {
$approved = 1;
}
}

I had: if($httpCode = "200")

I really do appreciate you guys trying to help out. *puts head between legs*

jatar_k




msg:1283754
 9:55 pm on Apr 12, 2006 (gmt 0)

hehe, done the same thing many times

no worries, it got me on [curl...] for a while and I learned a few things that I had forgotten while searching, so win all around ;)

vacorama




msg:1283755
 1:07 pm on Apr 13, 2006 (gmt 0)

haha... yeah, definitely been through that a few times..

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved