Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 警告curl_setopt()要求参数2为长字符串_Php_Json_Curl - Fatal编程技术网

Php 警告curl_setopt()要求参数2为长字符串

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 .

我总是犯这个卷曲错误

警告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 .= '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):无法打开流:没有这样的文件或目录该文件存在吗?这个代码甚至不在你最初的问题中。