Welcome to WebmasterWorld Guest from 54.198.87.238

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

cURL response code

Not showing the correct http response

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

10+ Year Member



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?

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

10+ Year Member



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.
5:17 pm on Apr 12, 2006 (gmt 0)

10+ Year Member



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?

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

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

10+ Year Member



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?

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

10+ Year Member



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...
8:25 pm on Apr 12, 2006 (gmt 0)

10+ Year Member



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.

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

10+ Year Member



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)...
9:31 pm on Apr 12, 2006 (gmt 0)

10+ Year Member



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*

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

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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 ;)

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

10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month