doudeng2057 2019-07-31 01:47
浏览 108

如何修复由JSON内容中的负数引起的php file_get_contents警告?

I'm trying to use file_get_contents() to perform an SQL query using Zoho's COQL API (https://www.zoho.com/crm/developer/docs/api/Get-Records-through-COQL-Query.html) to get a list of customers within a longitude and latitude boundary. When I pass my SQL statement, file_get_contents() fails to open the stream.

I've been troubleshooting this for the better part of two hours now, and from what I can tell, the issue only occurs when a negative number is present in the query. If I remove the hyphen, I'm able to perform a successful query and get a response from the server. I don't understand what's going on or how to fix it.

I've changed the longitude and latitude numbers for privacy, but otherwise this is the code I'm using.


$query = "select Last_Name, First_Name, Mailing_Street, Mailing_City, Mailing_State, Mailing_Zip, Latitude, Longitude
      from Contacts
      where (Latitude between 29.831755 and 29.889647)
      and (Longitude between -114.994548 and -115.069968)";

private function perform_query(){
        $data = json_encode(["select_query" => $this->query]);
        $result = file_get_contents($this->config['coql_url'], FALSE, stream_context_create([
            'http' => [
                'method' => 'POST',
                'header' => 'Content-Type: application/json; charset=utf-8' . "
" .
                "Authorization: Zoho-oauthtoken " . $this->access_token,
                'content' => $data
            ]
        ]));
        var_dump($http_response_header);
        var_dump($data);
        var_dump($result);
        return $result;
    }

Here's the output of the var_dump()s:

<b>Warning</b>:  file_get_contents(https://www.zohoapis.com/crm/v2/coql): failed to open stream: HTTP request failed! HTTP/1.1 401 
 in <b>/home2/.../src/coql.php</b> on line <b>54</b><br />
array(15) {
  [0]=>
  string(13) "HTTP/1.1 401 "
  [1]=>
  string(11) "Server: ZGS"
  [2]=>
  string(35) "Date: Wed, 31 Jul 2019 01:25:28 GMT"
  [3]=>
  string(44) "Content-Type: application/json;charset=utf-8"
  [4]=>
  string(18) "Content-Length: 87"
  [5]=>
  string(17) "Connection: close"
  [6]=>
  string(63) "Set-Cookie: ...; Path=/"
  [7]=>
  string(31) "X-Content-Type-Options: nosniff"
  [8]=>
  string(31) "X-XSS-Protection: 1; mode=block"
  [9]=>
  string(83) "Set-Cookie: crmcsr=...;path=/;Secure;priority=high"
  [10]=>
  string(16) "Pragma: no-cache"
  [11]=>
  string(23) "Cache-Control: no-cache"
  [12]=>
  string(38) "Expires: Thu, 01 Jan 1970 00:00:00 GMT"
  [13]=>
  string(71) "Set-Cookie: JSESSIONID=...; Path=/; Secure"
  [14]=>
  string(26) "X-Download-Options: noopen"
}
string(262) "{"select_query":"select Last_Name, First_Name, Mailing_Street, Mailing_City, Mailing_State, Mailing_Zip, Latitude, Longitude
      from Contacts
      where (Latitude between 29.831755 and 29.889647)
      and (Longitude between -114.994548 and -115.069968)"}"
bool(false)

How do I solve the problem?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行