【发布时间】:2019-02-25 12:32:01
【问题描述】:
我在 PHP 中使用 curl 获得以下 JSON 输出
卷曲:
$request = curl_init("{$config['root']}/api/tickets");
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, json_encode($body));
curl_setopt($request, CURLOPT_TIMEOUT, 30);
add_headers($request);
$response = curl_exec($request);
功能:
function add_headers($request) {
global $config;
$headers = array('Content-Type: application/json');
if (empty($config['accessClient'])) {
curl_setopt($request, CURLOPT_USERPWD, "{$config['user']}:{$config['password']}");
} else {
array_push($headers, "Access-Client-Token: {$config['accessClient']}");
}
curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
}
输出:
"{"amount":"100","description":"A ticket of 100.","payer":null,"successUrl":"http:\/\/localhost\/wordpress5\/ticket-confirmed.php","successWebhook":"http:\/\/localhost\/wordpress5\/ticket-confirmed-webhook.php","cancelUrl":"http:\/\/localhost\/wordpress5\/shop","orderId":"OID-1","expiresAfter":{"amount":1,"field":"hours"},"customValues":{}}"
卷曲响应是“
"{"Code":"Validation"}"
开发者控制台:
格式错误的 JSON 输出
注意:值来自 NetBeans 变量。 当我检查 Json 验证器的输出时,它变得无效只是因为输出开始和结束中的双引号,当我们将 json 输出分配给变量时,我认为这在 php 中还不错。
测试 Cyclos API here。 U:演示P:1234
【问题讨论】:
-
它是第 3 部分 API?
-
@Vel 是的,它的环
-
@Vel 你能帮我吗
-
您好,我没有 cyclos 帐户。所以我无法检查
-
无论是你的 curl 代码还是你的 add_headers 函数都不应该产生任何输出,所以显然有些事情你没有告诉我们。 (例如,也许您在
$response = curl_exec($request);之后有一个echo $response;,但您没有向我们展示?)
标签: php json wordpress curl netbeans