I have a request to a restful API (Note, it happens both with Invoke-WebRequest
and Invoke-RestMethod
):
$resp1 = Invoke-WebRequest -OutFile $clusterConfigZipFile -Uri $apiFolder -Body $fileContent -Method 'POST' -Credential $adminCredentials -ContentType "application/x-www-form-urlencoded" -ErrorAction SilentlyContinue -Verbose
I know it works ok because:
My problem is that code is returning nothing in $resp1
. I have read that it is a "feature" when you use -OutFile
.
Is there anyway to capture response or at least response code it PowerShell?
As documented , use the -Passthru
parameter if you want the response returned in addition to being written to a file.
-OutFile<String>
Saves the response body in the specified output file. Enter a path and file name. If you omit the path, the default is the current location.
By default,
Invoke-WebRequest
returns the results to the pipeline. To send the results to a file and to the pipeline, use thePassthru
parameter.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.