CakePHP 2 Form and trying to POST to it using curl
This is what I am trying to duplicate with curl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | -----------------------------1993502965129257581246610166 Content-Disposition: form-data; name="_method" POST -----------------------------1993502965129257581246610166 Content-Disposition: form-data; name="data[PrintLabel][printer]" 10 -----------------------------1993502965129257581246610166 Content-Disposition: form-data; name="data[PrintLabel][upload]"; filename="" Content-Type: application/octet-stream -----------------------------1993502965129257581246610166 Content-Disposition: form-data; name="data[PrintLabel][action]" print -----------------------------1993502965129257581246610166-- |
Curl POST to CakePHP Form
This is what is working with curl
1 2 3 4 5 6 7 8 | #!/bin/sh printer=10 curl --form _method=POST \ --form 'data[PrintLabel][upload]' =@. /ASN_R-34718415X-batch .xml \ --form 'data[PrintLabel][action]' =print \ --form 'data[PrintLabel][printer]' =${printer} \ http: //10 .197.3.190:8093 /project1/PrintLabels/xmlToPdf |
Powershell (version 5.x) POST to CakePHP Form
Important!: The following doesn't work on Powershell 7
If the file is named powershellPost.ps1
run it as follows:
1 | powershell.exe powershellPost.ps1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | $FilePath = "$($pwd)\ASN_R-34718415X-batch.xml" ; $fileBytes = [System.IO.File] ::ReadAllBytes( $FilePath ); $fileEnc = [System.Text.Encoding] ::GetEncoding( 'ISO-8859-1' ).GetString( $fileBytes ); $boundary = [System.Guid] ::NewGuid().ToString(); $LF = "`r`n" ; $bodyLines = ( "--$boundary" , "Content-Disposition: form-data; name=`"_method`"", "", " POST ", " -- $boundary ", " Content-Disposition: form-data; name=` "data[PrintLabel][printer]`"", "", 10, " -- $boundary ", " Content-Disposition: form-data; name=` "data[PrintLabel][upload]`"; filename=`"hijames.txt`"", " Content-Type: application/octet-stream ", "", $fileEnc, " -- $boundary ", " Content-Disposition: form-data; name=` "data[PrintLabel][action]`"$LF" , "print" , "--$boundary--$LF" ) -join $LF Invoke-RestMethod -Uri $URL -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines |
0 Comments