下面我用postman测试它返回响应但是当我检查PHP时它没有返回任何响应。请帮助我。
cURL文件创建:
$curl_file = curl_file_create(\Yii::$app->basePath.'/web/uploads/'.$uploadedFile->name,'pbix',$uploadedFile->baseName);
$params = ['file' => $curl_file];
cURL流程:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://***.***.**.***/v1.0/collections/**/workspaces/**/***?datasetDisplayName=new test",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $params,
CURLOPT_HTTPHEADER => array(
"authorization: key",
),
));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
答案 0 :(得分:2)
问题是参数中的空格。space
应替换为%20
。你需要做的如下:
$url="https://***.***.**.***/v1.0/collections/**/workspaces/3b09eff6-69ae-4932-9419-14eeb69a9dbd/***?datasetDisplayName=new test";
$curl_url=str_replace(" ","%20",$url);
或者您必须使用urlencode。在编码要在URL的查询部分中使用的字符串时使用。
$curl_url="https://***.***.**.***/v1.0/collections/**/workspaces/3b09eff6-69ae-4932-9419-14eeb69a9dbd/***?datasetDisplayName=urlencode(new test)";
然后
curl_setopt_array($curl, array(
CURLOPT_URL => $curl_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $params,
CURLOPT_HTTPHEADER => array(
"authorization: key",
),
));