Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I am trying to upload an app (.qvf) using the QRS API. I am using the powershell scripts for this.
The certificate I am using and all the other details that needs to be passed to the API seems fine. And also they are working fine for the other APIs. But for the upload API I am getting the following error:
C:\Users\310264586\Desktop\sample_ps.ps1 : FAILED to reach '': The remote server returned an error: (404) Not Found.
At line:1 char:1
+ .\sample_ps.ps1
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,sample_ps.ps1
Invoke-WebRequest : The remote server returned an error: (404) Not Found.
At C:\Users\310264586\Desktop\sample_ps.ps1:57 char:21
+ ... $response = Invoke-WebRequest $uploadCommand -Headers $headers -Metho ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$reloadMethod = "POST"
$filePath = "C:\app.qvf"
$senseServerHostName = 'https://***:4242'
# cross site scripting key
$xrfKey = "asjdklfjlkjasld**"
# Create a dictionary object that allows header storage in Rest call
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("X-Qlik-Xrfkey",$xrfKey)
$headers.Add("X-Qlik-User", "UserDirectory=internal;UserId=sa_repository")
$uploadFilter = "&name=TestApp"
$uploadPath = "/qrs/app/upload?xrfkey=$xrfKey"
$uploadCommand = $senseServerHostName + $uploadPath + $uploadFilter
$ns = "System.Security.Cryptography.X509Certificates"
$cert = New-Object "$ns.X509Certificate2"("C:\cert_key.p12","Qlik")
<# tried this
$body = @{
"FileName" = Get-Content($filePath) -Raw
}#>
try {
# Returns the response gotten from the server (we pass it on).
#
#$fileBin = [IO.File]::ReadAllBytes($filePath) tried this
$fileRes = Get-Content $filePath | Out-String
$contentType = "mutlipart/form-data"
#$enc = [System.Text.Encoding]::ASCII
#$encFile = $enc.GetString($fileBin) tried this
$response = Invoke-WebRequest $uploadCommand -Headers $headers -Method $uploadCommand -Certificate $cert -Body $fileRes -ContentType $contentType
}
catch [System.Net.WebException] {
Write-Error( "FAILED to reach '$URL': $_" )
throw $_
}
How should I send the QVF file in the body?
-Thanks