HSP from PHP

72 views
Skip to first unread message

njb...@gmail.com

unread,
Feb 2, 2017, 2:05:07 PM2/2/17
to A gathering place for the Open Rail Data community
I could do with some help with this call formatted in PHP. What have I done wrong?

<?PHP
$creds = '<<email>>:<<password>>';
$url = 'https://hsp-prod.rockshore.net/api/v1/serviceMetrics';
$data_array = array("from_loc"=>"BTN","to_loc"=>"VIC","from_time"=>"0700","to_time"=>"0800","from_date"=>"2016-07-01","to_date"=>"2016-08-01","days"=>"WEEKDAY");
$data = json_encode($data_array);
echo $data;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic {Base64($creds)}',
'Content-Type: application/json',
'Host: hsp-prod.rockshore.net',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
//echo json_decode($result);
echo $result;
?>

This returns a message Failed to decode basic access token. Thanks, Nick

Chris Northwood

unread,
Feb 2, 2017, 2:39:48 PM2/2/17
to njb...@gmail.com, A gathering place for the Open Rail Data community
you could maybe try CURLOPT_USERPWD as an alternative? Alternatively, you might find Guzzle (http://docs.guzzlephp.org/en/latest/) more usable than Curl.


--
You received this message because you are subscribed to the Google Groups "A gathering place for the Open Rail Data community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openraildata-talk+unsubscribe@googlegroups.com.
To post to this group, send an email to openraildata-talk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages