PowerFlex 3.x “SetPassword”REST API 调用返回“400 错误请求”

Summary: 使用 Powershell 与 VxFlexOS/PowerFlex REST API 交互时,函数“setPassword”返回“400 bad request”。但是,其他函数工作正常,例如“resetPassword”。 具体情况: 在 REST API 中使用自定义代码和“setPassword”函数设置登录用户的密码,VxFlexOS/PowerFlex 网关将返回错误请求“400”HTML 代码。但其他功能仍可正常运行,没有错误。 ...

This article applies to This article does not apply to This article is not tied to any specific product. Not all product versions are identified in this article.

Symptoms

在日志或命令行中,类似于以下内容的内容将显示“远程服务器返回错误:(400) Bad Request“:

image.png

Cause

某些具有较大正文有效负载的函数,如“setPassword”(需要 oldPassword 对象加值和 newPassword 对象加值)要求标头还包含内容类型“application/json”,以便 VxFlex REST API 正确解释后期调用。

Resolution

若要解决此问题,请使用 Web 请求提供内容类型,例如,PowerShell 中的以下代码需要将“-ContentType ”application/json“”添加到 Invoke-WebRequest 方法中才能成功发布“:

#format the user/pw hash in BASE64 to get it parsed by REST
$head = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("admin:Scaleio1234"))}
 
$head
#get token for authorization.
$r = Invoke-WebRequest -Uri https://192.168.199.76/api/login -Method Get -Headers $head -UseBasicParsing
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":" + $r.content.replace('"','')))
$header = @{'Authorization' = "Basic $token"}
$payload2 = @{
oldPassword = 'Scaleio1234'
newPassword = 'Scaleio123'
}
 
$body2 = Convertto-JSON -InputObject $payload2
 
 
 
Invoke-WebRequest -Uri https://192.168.199.76/api/instances/User/action/setPassword -Headers $header -Method Post -ContentType "application/json" -Body $body2

同样的事情可以从 Curl 或其他编程语言中完成:

curl -v -k -X POST -H "Content-Type:application/json" ...

 

受影响的版本

PowerFlex 3.x

Affected Products

PowerFlex Software

Products

PowerFlex rack, PowerFlex Appliance, PowerFlex custom node
Article Properties
Article Number: 000194607
Article Type: Solution
Last Modified: 14 Apr 2025
Version:  2
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.