This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
sendnas14714
I have the following code which works fine elsewhere, except in OctoberCMS. I've put the following code in the code section of the editor, but it just returns null when i login with a user. Is there something wrong with my code below?
function postToService($method, $urlAbs, $data = null) {
$dataJSON = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlAbs);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJSON);
curl_setopt($ch, CURLOPT_USERPWD, $_POST['username'] . ":" . $_POST['password']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($dataJSON))
);
$resultJSON = curl_exec($ch);
return json_decode($resultJSON);
}
function onStart() {
if (isset($_POST['username']) && isset($_POST['password'])) {
$data = array(
'UserName' => $_POST['username'],
'Password' => $_POST['password'],
'Area' => 2
);
var_dump($this->postToService('POST', 'https://example.com/api/authenticate', $data));
}
}
Last updated
1-2 of 2