【问题标题】:Error executing curl from php从 php 执行 curl 时出错
【发布时间】:2018-03-20 14:15:47
【问题描述】:

以下代码使用 POSTMAN 完美运行。当我尝试使用邮递员为 PHP 生成的代码时,它给了我错误。

原文代码:

curl -X POST \
  'http://111.93.2.38:8080/gsp/gsp/authenticate?grant_type=token' \
  -H 'cache-control: no-cache' \
  -H 'gspappid: 64AB7894D61644F3B5CA18B4738C700D' \
  -H 'gspappsecret: 70988876GEEEEG4504GB400G92B801E23686' \

PHP 代码:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "8080",
  CURLOPT_URL => "http://111.93.2.38:8080/gsp/gsp/authenticate?grant_type=token",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "gspappid: 64AB7894D61644F3B5CA18B4738C700D",
    "gspappsecret: 70988876GEEEEG4504GB400G92B801E23686",
    "postman-token: ff8278bb-b888-9fd3-6a55-780dafd58aa5"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

请帮帮我。

【问题讨论】:

标签: php linux curl


【解决方案1】:

你遇到什么样的错误,你能分享一下,以便我们帮助你吗? 如果出现超时错误,您可以尝试更改 CURLOPT_TIMEOUT => 30

的值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多