Why do I get the expected result but the HTTP code for the return value is int(0)?

Asked 2 years ago, Updated 2 years ago, 144 views

Below, I can get the results I expected to run curl_exec.
Both curl_getinfo results are int(0).

·What do you mean?
·Is the server setting related?

 curl_setopt_array($ch,[
    CURLOPT_RETURNTRANSFER = > true,
    CURLOPT_POST = > true,
    CURLOPT_POSTFIELDS=>http_build_query($hoge),
]);

curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_getinfo($ch,CURLINFO_RESPONSE_CODE);

json_decode(curl_exec($ch), true);

php http php-curl

2022-09-30 21:37

1 Answers

"All curl_getinfo results will be int(0)" means
I think that both curl_getinfo runs failed and False(0) was returned.

 curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_getinfo($ch,CURLINFO_RESPONSE_CODE);

As shown in , if you do not use the results of curl_getinfo (you do not substitute the results into variables or judge them by if statements, etc.), it is hard to understand that the results are all int(0).

If you don't want to use curl_getinfo, don't write it in the code.
If you write curl_getinfo in the code, use it properly.
If you do something half done, it will be difficult to clean up the mess.(I've had a hard time)


2022-09-30 21:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.