繁体   English   中英

PHP中的System Center Operations Manager(SCOM)1801 REST API身份验证

[英]System Center Operations Manager (SCOM) 1801 REST API Authentication in PHP

我正在用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错误。

我怎样才能解决这个问题? 我有什么想念的吗?

谢谢,
恩佐

您缺少请求正文。 使用NTLM身份验证时,请求正文应通知SCOM API您正在执行此操作。 为此,提交“ Windows”作为base-64编码的JSON正文,在您的代码中为空。 请参考以下示例(在PowerShell中,但应该可读): https : //community.squaredup.com/answers/question/scom-1801-rest-api/

换句话说,不要对您的PHP代码进行更改,而是:

$request = "Windows";
$request = utf8_encode($request);
$request = "\"".base64_encode($request)."\""; // should give you ["V2luZG93cw=="]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM