-
Notifications
You must be signed in to change notification settings - Fork 8.2k
[Invoke-WebRequest][PSVersion 6.0.2] Unable to set "expect" (100-continue) request-header field in multipart/form-data #7199
Description
Hi,
I'm trying to send en POST request with a file attatchment to a REST web server.
I need to wait for a 100 (Continue) response before sending the request body.
When i specify the "expect" request-header field it seems to be ignored/discard while the other fields do not (accept,user-agent or custom field).
Steps to reproduce
$head = @{
auth_token="123456";
accept="*/*";
expect="100-continue";
}
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$myFilePath = "myFile.zip"
$FileStream = [System.IO.FileStream]::new($myFilePath, [System.IO.FileMode]::Open)
$fileHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$fileHeader.Name = "uploadFile"
$fileHeader.FileName = "$myFilePath"
$fileContent = [System.Net.Http.StreamContent]::new($FileStream)
$fileContent.Headers.ContentDisposition = $fileHeader
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("application/octet-stream")
$multipartContent.Add($fileContent)
Invoke-WebRequest -Uri "http://MyRestServer/" -Method "POST" -Headers "$head" -Body "$MultipartContent"Expected behavior
--------- HTTP Headers ---------
{"connection":"Keep-Alive","content-type":"multipart/form-data; boundary="49442f36-68c8-4e57-a5d0-feb7f1ce292a"","accept":"/","user-agent":"Mozilla/5.0 (Windows NT 6.3; Microsoft Windows 6.3.9600; en-US) PowerShell/6.0.2","expect":"100-continue","auth_token":"123456","content-length":"79667491","host":"MyRestServer"}
Actual behavior
--------- HTTP Headers ---------
{"connection":"Keep-Alive","content-type":"multipart/form-data; boundary="49442f36-68c8-4e57-a5d0-feb7f1ce292a"","accept":"/","user-agent":"Mozilla/5.0 (Windows NT 6.3; Microsoft Windows 6.3.9600; en-US) PowerShell/6.0.2","auth_token":"123456","content-length":"79667491","host":"MyRestServer"}
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.2
PSEdition Core
GitCommitId v6.0.2
OS Microsoft Windows 6.3.9600
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0