【问题标题】:using curlto send POST request always outputs the result使用 curl 发送 POST 请求总是输出结果
【发布时间】:2015-04-12 11:24:51
【问题描述】:

我正在使用 curl 发送端口请求,而不使用此代码打印结果

$data = array('username' => 'username', 'password' => 'password');
$url = 'http://urlhere';
$ch = curl_init($url);
$postString = http_build_query($data, '', '&');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// or use this line curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

我在最后一行代码中使用了 1 和 true,但它总是在网页上打印结果。 curl不输出结果如何执行?

【问题讨论】:

    标签: php post curl request output


    【解决方案1】:

    必须工作,因为我在日常项目中使用相同的代码并在不打印的情况下取回数据

                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      • 2018-12-26
      • 1970-01-01
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多