PHP-如何检查Curl是否真的发布/发送请求?
我基本上使用Curl和PHP创建了一个脚本,用于向网站发送数据,例如主机、端口和时间。然后提交数据。我怎么知道Curl/PHP是否真的将这些数据发送到了web页面PHP-如何检查Curl是否真的发布/发送请求?,php,mysql,curl,Php,Mysql,Curl,我基本上使用Curl和PHP创建了一个脚本,用于向网站发送数据,例如主机、端口和时间。然后提交数据。我怎么知道Curl/PHP是否真的将这些数据发送到了web页面 $fullcurl = "?host=".$host."&time=".$time."; 想知道他们是否真的将数据发送到My MYSQL上的那些URL吗?为了确保curl发送了一些东西,你需要一个数据包嗅探器。 例如,你可以试试 我希望这能帮助你 Jerome Wagner您可以使用curl\u getinfo()获取响应的
$fullcurl = "?host=".$host."&time=".$time.";
想知道他们是否真的将数据发送到My MYSQL上的那些URL吗?为了确保curl发送了一些东西,你需要一个数据包嗅探器。 例如,你可以试试 我希望这能帮助你
Jerome Wagner您可以使用
curl\u getinfo()
获取响应的状态代码,如下所示:
// set up curl to point to your requested URL
$ch = curl_init($fullcurl);
// tell curl to return the result content instead of outputting it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// execute the request, I'm assuming you don't care about the result content
curl_exec($ch);
if (curl_errno($ch)) {
// this would be your first hint that something went wrong
die('Couldn\'t send request: ' . curl_error($ch));
} else {
// check the HTTP status code of the request
$resultStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($resultStatus == 200) {
// everything went better than expected
} else {
// the request did not complete as expected. common errors are 4xx
// (not found, bad request, etc.) and 5xx (usually concerning
// errors/exceptions in the remote script execution)
die('Request failed: HTTP status code: ' . $resultStatus);
}
}
curl_close($ch);
供参考:
或者,如果您向某种返回请求结果信息的API发出请求,则需要实际获取该结果并对其进行解析。这对于API来说非常具体,但下面是一个示例:
// set up curl to point to your requested URL
$ch = curl_init($fullcurl);
// tell curl to return the result content instead of outputting it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// execute the request, but this time we care about the result
$result = curl_exec($ch);
if (curl_errno($ch)) {
// this would be your first hint that something went wrong
die('Couldn\'t send request: ' . curl_error($ch));
} else {
// check the HTTP status code of the request
$resultStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($resultStatus != 200) {
die('Request failed: HTTP status code: ' . $resultStatus);
}
}
curl_close($ch);
// let's pretend this is the behaviour of the target server
if ($result == 'ok') {
// everything went better than expected
} else {
die('Request failed: Error: ' . $result);
}
不,我听说我需要regex或curlopt。你好。我想我误解了你的问题。curl的工作和mysql之间有什么关系?基本上,curl从mysql获取URL,然后将post数据发送给他们。