如何知道 CURL return 是真还是假?
How to know if CURL return true or false?
以前我在使用 CURL
从 http 请求打印内容 body 时遇到问题,我解决了添加这个问题:
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
但现在如果我 print_r(curl_exec($ch))
我只有 body 而不是 true 或 false.
我在内容中有这个结构body:
ok: true
result:
message_id: 12186
from:
id: 12345678
is_bot: true
first_name: "bot"
username: "my bot"
chat:
id: 12345
first_name: "Gio"
last_name: "Bor"
username: "giobor"
type: "private"
date: 1571676256
text: "okk"
那么我怎样才能同时拥有两者呢?
使用 curl_errno()
in order to determine whether or not an error occurred. If the return value is 0
then the request succeeded, otherwise there was an error. Additionally, use curl_error()
接收包含相应错误消息的字符串以进行调试。
以前我在使用 CURL
从 http 请求打印内容 body 时遇到问题,我解决了添加这个问题:
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
但现在如果我 print_r(curl_exec($ch))
我只有 body 而不是 true 或 false.
我在内容中有这个结构body:
ok: true
result:
message_id: 12186
from:
id: 12345678
is_bot: true
first_name: "bot"
username: "my bot"
chat:
id: 12345
first_name: "Gio"
last_name: "Bor"
username: "giobor"
type: "private"
date: 1571676256
text: "okk"
那么我怎样才能同时拥有两者呢?
使用 curl_errno()
in order to determine whether or not an error occurred. If the return value is 0
then the request succeeded, otherwise there was an error. Additionally, use curl_error()
接收包含相应错误消息的字符串以进行调试。