我正在用PHP开发一个集成类,以使用新的REST API接口访问SCOM数据。我找不到使用PHP连接到API的其他文档。到目前为止,我的情况是:
$url = "http://scomserver/OperationsManager/authenticate";
$username = 'myuser';
$password = 'myPassw0rd';
$request = "";
$cookie = tempnam("/tmp", "CURLCOOKIE");
$requestHeaders = array('Content-Type, application/json; charset=utf-8');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, implode("\r\n", $requestHeaders));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, count($request));
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, -1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($ch);
$response = curl_getinfo( $ch );
curl_close($ch);
使用此代码,我得到以下错误:
{“ errorMessage”:“传递的参数不能为空”,“ errorTrace”:“”}
并且IIS日志报告400错误。
我该如何解决?我有什么想念的吗?
谢谢,
恩佐
答案 0 :(得分:0)
您缺少请求正文。使用NTLM身份验证时,请求正文应通知SCOM API您正在执行此操作。为此,提交“ Windows”作为base-64编码的JSON正文,在您的代码中为空。请参考以下示例(在PowerShell中,但应该可读):https://community.squaredup.com/answers/question/scom-1801-rest-api/。
换句话说,不要更改您的PHP代码,而是:
if (P2=1) then
where (state='SP' and situation='stopped')
elseif (P2=2)
where (state='MG' and situation='moving')