问题
I'm trying to develop a PS script that install app package to Hololens via the device portal APIs. Looking for some troubleshooting tips on the 400 BAD REQUEST response.
Here are the references I used : https://docs.microsoft.com/en-us/windows/mixed-reality/device-portal-api-reference
END POINT /api/app/packagemanager/package (POST)
$user = 'snarain'
$pass = 'snarain'
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
$FilePath = 'C:\Users\snarain\Downloads\My HololensApp.appxbundle'
Invoke-RestMethod -Uri 'http://127.0.0.1:10080/api/app/packagemanager/package?package=My%20HololensApp.appxbundle' -Headers $Headers -Method Post -InFile $FilePath -ContentType 'multipart/form-data'
The output is Invoke-RestMethod : The remote server returned an error: (400) Bad Request
. However, I am able to use Postman to hit the end point and upload the app successfully. I saved the request from POSTMAN to its curl equivalent here it is, for the experts to quickly debug it.
--url 'http://127.0.0.1:10080/api/app/packagemanager/package?package=My%20HololensApp.appxbundle' \
--header 'Authorization: Basic c25hcmFpbjpzbmFyYWlu' \
--header 'Postman-Token: c6613653-3ff0-43c1-896c-63d62b125277' \
--header 'cache-control: no-cache' \
--header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
--form '=@C:\Users\snarain\Downloads\My HololensApp.appxbundle'```
回答1:
The answer from jklemmack on this post helped solve this problem. Also I should be using ISO-8859-1 encoding instead of UTF-8 to make the appxbundle read successful.
powershell invoke-restmethod multipart/form-data
Solved !
来源:https://stackoverflow.com/questions/55424632/error-on-ps-script-that-installs-app-to-hololens-using-device-portal-apis