为什么我在使用宁静的离子应用程序时得到HttpErrorResponse?

时间:2019-04-18 01:46:58

标签: php json angular curl ionic-framework

我正在设置返回JSON的服务器,但是,执行curl后会出现错误

我可以在chrome和postmen中得到响应,但在离子上却失败

<?php
  $strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
  $ch = curl_init();
  $message='vendor=mobi&username=x&sid='.session_id().'';
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_URL,'http://xxx);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS,$message);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_COOKIE, $strCookie );
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  curl_setopt($ch, CURLOPT_TIMEOUT, 800);
  $server_output = curl_exec($ch);
  curl_close ($ch);
  $data=array();
  $data=array('a'=>'b');
  echo json_encode($data);
?>

我希望输出'a'=>'b',但是ionic使用数据订阅将其获取HttpErrorResponse

1 个答案:

答案 0 :(得分:0)

应删除

$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
curl_setopt($ch, CURLOPT_COOKIE, $strCookie );

并将其更改为

curl_setopt ($ch, CURLOPT_COOKIEFILE, '');