Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I can't find the reason this command in powershell raise an error
$hdrs = @{} $cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'} $Body = @{ $url = "https://XXXXX.XXXXXX.XXX:4242/qrs/app/import?name=test_import&xrfkey=1234567890123456" |
Error:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:15 char:13
+ $response = Invoke-RestMethod -Uri $url -Method POST -Headers $hdrs - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
PS: I can run other POST or Get command
This works for me:
$hdrs = @{}
$hdrs.Add("X-Qlik-Xrfkey","examplexrfkey123")
$hdrs.Add("X-Qlik-User", "UserDirectory=INTERNAL; UserId=sa_api")
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}
$Data = Get-Content C:\ProgramData\Qlik\Sense\Host.cfg
$FQDN = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($($Data)))
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/app/upload?keepData=true&name=Some+Name&xrfkey=examplexrfkey123" -Method Post -Headers $hdrs -ContentType 'application/vnd.qlik.sense.app' -Certificate $cert -InFile 'C:\Temp\Random Data.qvf'
This works for me:
$hdrs = @{}
$hdrs.Add("X-Qlik-Xrfkey","examplexrfkey123")
$hdrs.Add("X-Qlik-User", "UserDirectory=INTERNAL; UserId=sa_api")
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}
$Data = Get-Content C:\ProgramData\Qlik\Sense\Host.cfg
$FQDN = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($($Data)))
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/app/upload?keepData=true&name=Some+Name&xrfkey=examplexrfkey123" -Method Post -Headers $hdrs -ContentType 'application/vnd.qlik.sense.app' -Certificate $cert -InFile 'C:\Temp\Random Data.qvf'