Skip to content

Commit

Permalink
Merge pull request #28 from PetriAsi/develop
Browse files Browse the repository at this point in the history
remove content-type headers from form name value pairs
  • Loading branch information
PetriAsi authored Dec 13, 2021
2 parents 0499724 + 43d8a88 commit f389a75
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions WilmaPSWorker/Public/Send-WPSWAttachment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,47 @@ function Send-WPSWAttachment (){

$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()

#content-type headers for name values makes wilma confused
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "formkey"
$StringContent = [System.Net.Http.StringContent]::new($WPSWSession.Result.FormKey)
$StringContent.Headers.ContentDisposition = $stringHeader
$res = $StringContent.Headers.Remove('Content-Type')
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "formid"
$StringContent = [System.Net.Http.StringContent]::new($form_id)
$StringContent.Headers.ContentDisposition = $stringHeader
$res = $StringContent.Headers.Remove('Content-Type')
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "targetid"
$StringContent = [System.Net.Http.StringContent]::new($card_id)
$StringContent.Headers.ContentDisposition = $stringHeader
$res = $StringContent.Headers.Remove('Content-Type')
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "targetdb"
$StringContent = [System.Net.Http.StringContent]::new($database_ids[$Database])
$StringContent.Headers.ContentDisposition = $stringHeader
$res = $StringContent.Headers.Remove('Content-Type')
$multipartContent.Add($stringContent)


$multipartFile = $fileItem.FullName
$FileStream = [System.IO.FileStream]::new($multipartFile, [System.IO.FileMode]::Open)
$fileHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$fileHeader.Name = "files"
$fileHeader.FileName = $fileItem.Name
$fileContent = [System.Net.Http.StreamContent]::new($FileStream)
$fileContent.Headers.ContentDisposition = $fileHeader
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("application/octet-stream")
if ((Split-Path -Path $fileItem.Name -Extension) -eq '.pdf' ){
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("application/pdf")
} else {
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("application/octet-stream")
}
$multipartContent.Add($fileContent)


Expand Down

0 comments on commit f389a75

Please sign in to comment.