Php 警告curl_setopt()要求参数2为长字符串
我总是犯这个卷曲错误 警告curl_setopt()要求参数2为长字符串 curl_setopt()要求参数2为长字符串,在706的/var/www/mbl.domain.com/html/admin/functions/api/jobs_send.php中给出 代码:Php 警告curl_setopt()要求参数2为长字符串,php,json,curl,Php,Json,Curl,我总是犯这个卷曲错误 警告curl_setopt()要求参数2为长字符串 curl_setopt()要求参数2为长字符串,在706的/var/www/mbl.domain.com/html/admin/functions/api/jobs_send.php中给出 代码: $request = urlencode($xml); $url = 'http://integrated.com/1.3'; $query = 'token=' . $token . '&'; $query .
$request = urlencode($xml);
$url = 'http://integrated.com/1.3';
$query = 'token=' . $token . '&';
$query .= 'idomain=' . $idomain . '&';
$query .= 'cdomain=' . $cdomain . '&';
$query .= 'request=' . $request;
if(!$ch = curl_init()){
die("Could not init cURL session.\n");
}
curl_setopt($ch, CURLOPT_ENCODING , "gzip"); // we are making our api call fast by 70%
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDSIZE, sizeof($query));
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 40); //timeout in seconds
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
$result = curl_exec($ch);
curl_close($ch);
$xmlObj = simplexml_load_string($result,"SimpleXMLElement", LIBXML_NOCDATA);
第706行:
curl_setopt($ch, CURLOPT_POSTFIELDSIZE, sizeof($query));
如何解决这个问题?在PHP中没有像
CURLOPT\u POSTFIELDSIZE
这样的选项。当您指定CURLOPT\u POSTFIELDS
时,它会自动为您在内部设置
由于PHP看到未定义的常量CURLOPT\u POSTFIELDSIZE
,将其转换为字符串(“CURLOPT\u POSTFIELDSIZE”
),并将其传递到函数中,因此会出现错误。这会导致错误,因为所有CURLOPT.*
常量实际上都是整数。(未定义的常量到字符串的转换将引发警告;如果您正在记录警告/错误,它将显示在您的日志中。)
另外:虽然没有引起您的问题,但还是出现了一个错误:
sizeof($string)==1
sizeof
是count
的别名,它为标量返回1
。对于字符串的长度,您希望使用strlen($string)
。@Coci相同的错误?那么,在您删除CURLOPT\u POSTFIELDSIZE
行之后,它抱怨哪一行?当我删除这一行时,它会给我一次require\u(/var/www/mbl.domain.com/html/admin/functions/api/jobs\u send.php):无法打开流:没有这样的文件或目录该文件存在吗?这个代码甚至不在你最初的问题中。