Uploading file to HTTP via Powershell
<p>We have a php site that uploads pictures to server, simple jpg file with correct naming. Problem is that we need to upload sometimes couple of hundred of them at a time, but php accepts only 1 at a time, renames them and uploads. I have done file operations in PS quite well, but fail to upload.</p>

<p>PHP part related to upload (as far as I can tell) looks like this: <code>&lt;form name='' id='' enctype='multipart/form-data' method='POST' action='/picture_upload.php' target='_self'  onsubmit="default_on_submit(event)"&gt;</code></p>

<p>I checked Google, related topics here as well, and got to this:</p>

<pre><code>$uri = "http://example.com/"
$pwd = ConvertTo-SecureString 'MyPassword' -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ('myuser', $pwd)
$contentType = "multipart/form-data"
    $body = @{
        "FileName" = Get-Content($uploadPath) -Raw
    }
    Invoke-WebRequest -Uri $uri -Method Post -ContentType $contentType -Body $body
</code></pre>

<p>I have checked <code>$uploadPath</code> and it is correct <code>C:\Folder\file.jpg</code>. I use credentials that I use to log in to site where I can upload these pictures via GUI. </p>

<p>I have tried switching between POST and PUT, with no changes.</p>

<p>Replacing <code>http://example.com</code> with <code>http://example.com/file.jpg</code> also provided no difference. Unsure, which is correct way to use POST.</p>

<p>We have McAffe web gateway in company, but I'm running script with user that bypasses it, so it's not causing this.</p>

<p>Current error message that I'm getting is:
"Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a receive."</p>

<p>Any help would be greatly appreciated! And sorry if this has been already solved and I've simply missed an entry!</p>

<p>P.S. I have also tried this - <a href="https://stackoverflow.com/questions/25356228/powershell-script-to-upload-log-file-from-local-system-to-http-url">Powershell script to Upload log file from local system to http URL</a>, and it returns <code>Exception calling "UploadFile" with "3" argument(s): "An exception occurred during a WebClient request."</code></p>