1
我有下面的CMD的curl请求工作正常,但是我需要将它转换为下面的函数bt,因为某些原因它没有这样做。为什么?如何使用-X PUT参数和发布数据将核心Curl请求转换为PHP代码请求?
curl -i 'http://localhost:7557/presets/inform' -X PUT --data '{ "weight": 0, "precondition": "{\"_deviceId._SerialNumber\":\"C8Bsdsd5E372\"}", "configurations": [ { "type": "value", "name": "InternetGatewayDevice.Time.NTPServer1", "value": "ntp1.sddsd.com" }, { "type": "value", "name": "InternetGatewayDevice.Time.NTPServer3", "value": "ntp.dfdfkdshfksfd.org" } ] }'
我写了下面的代码作为PHP的功能,但似乎与
响应代码405失败(不允许的方法,我相信这个问题是PUT请求)
405 Method Not Allowed
$request='{ "weight": 0, "precondition": "{\"_deviceId._SerialNumber\":\"C8Bjkjkjj5E372\"}", "configurations": [ { "type": "value", "name": "InternetGatewayDevice.Time.NTPServer1", "value": "ntp1.sssdssd.com" }, { "type": "value", "name": "InternetGatewayDevice.Time.NTPServer3", "value": "ntp.dfdfkdshfksfd.org" } ] }';
$location='http://localhost:7557/presets/inform';
$response=curlRequest($request,$location);
function curlRequest($request, $location)
{
$ch = curl_init($location);
$curlOptions = array(
CURLOPT_URL => $location,
// CURLOPT_RETURNTRANSFER => true,
// CURLOPT_FOLLOWLOCATION => true,
// CURLOPT_MAXREDIRS => 10,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $request,
CURLOPT_PROXY => 'proxy.example.com',
CURLOPT_PROXYPORT => 8080 ,
CURLOPT_TIMEOUT => SOAP_CONN_TIMEOUT,
CURLOPT_SSLVERSION => 3,
CURLOPT_SSL_VERIFYPEER => false,
);
//
curl_setopt_array($ch, $curlOptions);
$response = curl_exec($ch) or die (curl_error($ch));
return $response;
}