Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Curl:Shell脚本的替代Php代码_Php_Shell_Curl - Fatal编程技术网

Curl:Shell脚本的替代Php代码

Curl:Shell脚本的替代Php代码,php,shell,curl,Php,Shell,Curl,我正在尝试将shell代码转换为php。下面的代码在通过shell运行时运行良好,但我想用php编写代码 URL="example.com" curl -k \ -w '\nHTTP STATUS: %{http_code}\n'\ -F "property_id[]=92cf91e5-9032-5e03-8d78-ff1e3af7d9d0" \ -F "property_id[]=6e6b2fbe-75c3-5896-aab0-6d809d6d4ac1" \ -F "property_id[

我正在尝试将shell代码转换为php。下面的代码在通过shell运行时运行良好,但我想用php编写代码

URL="example.com"
curl -k \ -w '\nHTTP STATUS: %{http_code}\n'\

-F "property_id[]=92cf91e5-9032-5e03-8d78-ff1e3af7d9d0" \
-F "property_id[]=6e6b2fbe-75c3-5896-aab0-6d809d6d4ac1" \
-F "property_id[]=c96d6baf-5d6c-564f-9cc4-7ed446e7785c" \
-X 'POST' "$URL" 
我尝试了以下操作,但出现了“未知错误”

$params = "--ABC1234\r\n"
. "Content-Type: application/x-www-form-urlencoded\r\n"
. "--ABC1234\r\n"
. "Content-Type: application/x-www-form-urlencoded\r\n"
. "Content-Disposition: form-data; name=\"property_id[]\" 8219cd38-b5c9-4dc6-a119-c983cf1d844b \r\n"
. "\r\n"
. "--ABC1234--";
$request_headers[] = 'Content-Length: ' . strlen($params);
$request_headers[] = 'Content-Type: application/x-www-form-urlencoded;     boundary='. $multipart_boundary;
$ch = curl_init($posturl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$reply = curl_exec($ch);
echo "<pre>";
print_r($reply);
$params=“--ABC1234\r\n”
. “内容类型:application/x-www-form-urlencoded\r\n”
. “--ABC1234\r\n”
. “内容类型:application/x-www-form-urlencoded\r\n”
. “内容处置:表单数据;名称=\“属性\u id[]”8219cd38-b5c9-4dc6-a119-c983cf1d844b\r\n”
. “\r\n”
. “--ABC1234--”;
$request_headers[]=“内容长度:”。斯特伦($params);
$request_headers[]='内容类型:application/x-www-form-urlencoded;边界='$多部分边界;
$ch=curl_init($postrl);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
curl_setopt($ch,CURLOPT_HTTP_VERSION,curl_HTTP_VERSION_1_0);
curl_setopt($ch,CURLOPT_HTTPHEADER,$request_headers);
$reply=curl_exec($ch);
回声“;
打印(回复);

提前感谢

终于找到了解决方案。非常简单。


不要问“为我转换此代码”,你应该问,“我尝试了这个,但我得到了以下错误,我尝试了这个和那个来修复它”——记住用相应的信息替换这个和那个。感谢回复,实际上我并没有收到任何错误,我正在处理getaroom api。它正在发送消息“未知错误”。你能给出你正在使用的url吗?RamRaider:*********************************身份验证令牌=*****************************。。。我应该向您发送api密钥和身份验证密钥吗?这是秘密钥匙。。。我应该在哪里共享?不,不要共享你的钥匙
$posturl="https://availability.getaroom.com/api/1.1/room_availability?transaction_id=***&check_in=08/18/2015&check_out=08/19/2015&rooms=1&adults=2&cancellation_rules=1&api_key=**************&auth_token=*********************&currency=AUD";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$posturl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"property_id=1234567890");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$getaroomsearch = new SimpleXMLElement(curl_exec($ch));
curl_close ($ch);