【问题标题】:Why I get the HttpErrorResponse in ionic app using restful?为什么我在使用 restful 的 ionic 应用程序中得到 HttpErrorResponse?
【发布时间】:2019-09-08 07:42:09
【问题描述】:

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

我可以在 chrome 和 postmen 中得到响应,但在 ionic 中失败

<?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

【问题讨论】:

  • 问题在:$strCookie = 'PHPSESSID='。 $_COOKIE['PHPSESSID'] 。 ';路径=/';

标签: php json angular curl ionic-framework


【解决方案1】:

应该删除

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

并将其更改为

curl_setopt ($ch, CURLOPT_COOKIEFILE, '');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-25
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    相关资源
    最近更新 更多