Error on PS script that installs app to Hololens using device portal APIs

↘锁芯ラ 提交于 2019-12-11 10:27:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!