public static function authenticate($project_url, $username, $password, $requestParams = array())
{
$url = fix_parse_url($project_url);
$response = SimpleHTTP::send('POST', $url['host'], $url['port'], $url['path'], array_merge($requestParams, array('a' => 'authenticate', 'username' => $username, 'password' => $password)));
if ('200' != $response['status_code']) {
throw new Exception("Invalid status code `{$response['status_code']}' returned from server `{$url['host']}'.");
}
$response = trim($response['body']);
if ('' === $response) {
throw new Exception("Unable to authenticate project, no content returned from `{$url['host']}{$url['path']}'.");
}
if ('#S#' == substr($response, 0, 3)) {
// returning ticket
return substr($response, 3);
}
throw new Exception(substr($response, 3));
}