PHP卷曲脚本响应错误消息但POSTMAN有效吗?

时间:2015-10-20 11:22:03

标签: php json curl

以下php代码正在发布man man app但不是curl php脚本。 卷曲代码正确,但给出的反应只有“错误”#39;同一个参与者正在研究邮递员应用程序。

<?php

$url = 'https://example.com/relay/relay/relay/device/XXXX/session/ZZZZZZZZZZZZZ/port_3480/data_request?id=scene&action=create';

$AuthToken = 'xxxxxx';
$AuthSigToken = 'YYYYY';

$aPostData = array('json' => '{"scene_name":"om","name":"om","groups":[{"delay":0,"actions":[{"device":"14","service":"urn:upnp-org:serviceId:HVAC_UserOperatingMode1","action":"SetModeTarget","arguments":[{"name":"NewModeTarget","value":"CoolOn"}]}]}],"triggers":[{"name":"tttttttt","enabled":1,"device":"12","template":"1","arguments":[{"id":1,"value":"0"}]}],"timers":[],"lua":"","users": "","modeStatus": "0","id": 1000001}');


$userAgent = $_SERVER['HTTP_USER_AGENT'];

  $ch = curl_init ($url);     
  curl_setopt($ch, CURLOPT_USERAGENT, $userAgent );
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  //curl_setopt($ch, CURLOPT_HEADER, 0);

  curl_setopt($ch, CURLOPT_HEADER, 1);
  curl_setopt($ch, CURLINFO_HEADER_OUT, true);

  curl_setopt($ch, CURLOPT_HTTPHEADER, array("MMSAuth:$AuthToken","MMSAuthSig:$AuthSigToken"));

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  //curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
  //curl_setopt($ch, CURLOPT_TIMEOUT, 60); //timeout in seconds

 if($aPostData != null)
  {
   $fields_string = '';
   foreach($aPostData as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
   $fields_string = rtrim($fields_string, '&');
   curl_setopt($ch,CURLOPT_POST, count($aPostData));
   curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
  }

$result = curl_exec($ch);
$error = curl_error($ch);

curl_close ($ch);   
echo '<pre>';
print_r($error);

echo '@result=>';
print_R($result);

?>

当我有打印结果时,显示错误,如

 @result=>HTTP/1.1 200 OK
    content-Type: 
    Transfer-Encoding: chunked
    Date: Tue, 20 Oct 2015 11:09:34 GMT
    Server: lighttpd/1.4.29

ERROR

0 个答案:

没有答案