【问题标题】:What is wrong in this cURL code, in PHP? [closed]这个 cURL 代码在 PHP 中有什么问题? [关闭]
【发布时间】:2015-07-31 05:29:48
【问题描述】:

我在这里问了一个问题:Send JSON by cURL always returns "No access"

一位好心人通过以下代码回答了我:

<?php

//API URL
$url = 'http://www.example.com/test.php';
$data = "?code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b"

//Initiate cURL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Execute the request
$result = curl_exec($ch);

?>

但是,我无法运行它。它返回一个错误:

解析错误:语法错误,第 8 行 D:\XAMPP\htdocs\test.php 中的意外 T_VARIABLE

我在自己的工作中使用 PHP 5.3

有什么可以解决的吗?

【问题讨论】:

    标签: php curl


    【解决方案1】:

    $data = "?code=Sh9QA&amp;token=0982ff3066a3c60dbd3ecf9bcafc801b" 之后您错过了;

    【讨论】:

      【解决方案2】:

      第 5 行缺少分号;

      <?php
      
      //API URL
      $url = 'http://www.example.com/test.php';
      $data = "?code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b"; //here
      
      //Initiate cURL.
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url . $data);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      
      //Execute the request
      $result = curl_exec($ch);
      
      ?>
      

      【讨论】:

      • 为什么是-1?请添加评论。
      猜你喜欢
      • 2014-08-12
      • 2013-06-23
      • 1970-01-01
      • 1970-01-01
      • 2015-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多