通过JSON端点

时间:2016-01-18 15:41:59

标签: php json curl

我需要通过PHP中的JSON Endpoint接收数据,有人可以帮助我吗?

我如何通过以下方式接收数据:

curl https://formz.herokuapp.com/api/forms/e382704d/submissions -H'授权:令牌令牌=" xxxxxxxxxxxxx"'

2 个答案:

答案 0 :(得分:0)

使用curlCURLOPT_HTTPHEADER

$ch = curl_init();
$headers = array('Authorization: Token token="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"');

curl_setopt($ch, CURLOPT_URL,"https://formz.herokuapp.com/api/forms/e382704d/submissions");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$output = curl_exec ($ch);
curl_close ($ch);

print $output;

应该给你输出

答案 1 :(得分:0)

我找到了解决方案

就是这样。

$access_key = 'TOKEN HERE';

$curl = curl_init( 'https://formz.herokuapp.com/api/forms/e382704d/submissions' );

curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Authorization: Token ' . $access_key ) );

curl_exec( $curl );