http - Upload multiple files from Powershell script -


I have a webpage that can post an html form in this way:

 < Code> & lt; Form action = "x" method = "post" encrypt = "multipart / form-data" & gt; & Lt; Input name = "xfa" type = "file" & gt; & Lt; Input name = "pdf" type = "file" & gt; & Lt; Input type = "submit" value = "submit" & gt; & Lt; / Form & gt;  

Note that two type = "file" elements are

How can I send scripts to the PowerLL script?

I found, but it can only handle one file.

Thank you for taking your time. /P>

I am currently crafting multilingual HTTP posts with PowerShell. I hope the code below is useful for you.

  • PowerShell can upload itself not multipart forms.
  • There are not many samples about it. I made the code based on and
  • Of course, the off-reserve method requires PowerShell 3.0, but the code in the above links shows how to do it. , It's also running in Windows XP.

Good luck! Please tell if you got this job.

 class = "lang-cs prettyprint-override">  function text-result {param ([parameter (mandatory = $ true, condition = 1)] [ValidateScript ({Test-Path -PathType Leaf $ String} $ [= string] $ [ResultFilePath], [parameter (mandatory = $ true, condition = 2)] [System.URI] $ ResultURL) $ fileBin = [IO.File]:: ReadAllBytes ($ ResultFilePath) $ computer = $ Env: Byte-input for COMPUTERNAME # string (without changing anything) # $ enc = [System.Text.Encoding] :: GetEncoding ("iso-8859-1") $ fileEnc = $ Enc.GetString ($ fileBin ) & Lt; # # PowerShell does not support built-in support for 'multipart' (i.e. binary file upload compatible) #file So we have to do a craft ... # # It is similar: # $ curl -i -F "file =@file.any" -F "computer = MYPC" http: // url # # limit Is not guaranteed to be present in the data being sent (i.e. the string is quite long) # # Note: The protocol line is very accurate about receiving the number of feeds (both CRL or LF work). # & Gt; $ Range = [System.Guid] :: NewGuid (). ToString () # $ LF = "` n "$ bodyLines = (" - $ border "," content-presentation: form-data; name = `" file `$ LF ', # filename = optional $ fileEnc," - $ Try the $ lf {# returns the response from the server}, "limit", "content-dispute: form-data; name =` computer` "$ LF", $ computer, "- $ limit- - $ lf") (We pass it) # Attach-Rustommouth-URI $ url- Law post -entent type "Multipart / form-data; Catch = "$ limit`" "-Timeout SEC 20-Bound $ Body Lines Hold [system.net.web expansion] {write-error (failed to reach" $ url: $ _ ") $ $ 8 }}  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -