0

I'm trying to query data from another website by using PHP curl_setopt as below function, But I don't know to valid when my partner sever get any error as below description.

    [Server Error 5xx]
    500="Internal Server Error"
    501="Not Implemented"
    502="Bad Gateway"
    503="Service Unavailable"
    504="Gateway Timeout"
    505="HTTP Version Not Supported"


   public function getNumber() {

        $url = "http://website/PalmHallServer_kl/!queryLuckNumberRecordByPeriods.action";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: Json'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $contents = curl_exec($ch);
        $res = false;
        if ($contents) {
            $res = TRUE;
        } else {
            $res = FALSE;
        }
        echo json_encode(array("res" => $res, 'data' => $contents));
    }

1 Answer 1

1

First tell curl that you want to see the headers returned

curl_setopt($ch, CURLOPT_HEADER, true); 

Then you can get Response code using

$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

To see all the information contained in the response headers you can do

print_r(curl_getinfo($ch));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.