PHP_api接口教程(5)
发布时间:2021-06-06
发布时间:2021-06-06
{
$postBodyString .= "$k=" . urlencode($v) . "&"; } else {
$postMultipart = true; } }
unset($k, $v);
curl_setopt($ch, CURLOPT_POST, true); if ($postMultipart) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); } else {
curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1)); } }
$reponse = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception(curl_error($ch),0); } else {
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (200 !== $httpStatusCode) {
throw new Exception($reponse,$httpStatusCode); } }
curl_close($ch); return $reponse; }
protected $responseTxt)
//文件上传用 multipart/form-data,否则用 www-form-urlencoded
function logCommunicationError($apiName, $requestUrl, $errorCode,