title: Invoke-WebRequest fails for a large file
body: <p>Following issue: 
  Using the power shell script below works for transferring a .war file from Server A to Server B via the tomcat manager ONLY when size of the war file is somewhat below 4MB. Everything above that size fails with</p>
  
  <blockquote>
    <p>Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
    At C:\Temp\deploy.ps1:25 char:2
    + (Invoke-WebRequest -InFile "C:\Temp\fancy.war" -URI "https: ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand</p>
  </blockquote>
  
  <p>Code that I run via PowerShell on Server A is:</p>
  
  <pre><code>Set-PSDebug -Trace 1
  $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
  [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
  
  add-type @"
  using System.Net;
  using System.Security.Cryptography.X509Certificates;
  public class TrustAllCertsPolicy : ICertificatePolicy {
      public bool CheckValidationResult(
          ServicePoint srvPoint, X509Certificate certificate,
          WebRequest request, int certificateProblem) {
          return true;
      }
  }
  "@
  [System.Net.ServicePointManager]::CertificatePolicy = New-Object 
  TrustAllCertsPolicy
  $user = "admin"
  $pass = "loveit"
  
  $secpass = ConvertTo-SecureString $pass -AsPlainText -Force
  $credential = New-Object System.Management.Automation.PSCredential($user, $secpass)
  (Invoke-WebRequest -InFile "C:\Temp\fancy.war" -URI "**https**://host99.some.domain:443/manager/text/deploy?path=/fancy&amp;update=true" -Method PUT -Credential $credential -ContentType 'application/zip' -UseBasicParsing -TimeoutSec 120)
  </code></pre>
  
  <p>I also played around with the server.xml of the tomcat8 and web.xml of the tomcat manager as mentioned in the post <a href="https://stackoverflow.com/questions/5109112/how-to-deploy-a-war-file-in-tomcat-7/15360585#15360585">How to deploy a war file in Tomcat 7</a></p>
  
  <p>As seen, with 50 MB I am on the safe side.</p>
  
  <p>\webapps\manager\WEB-INF\web.xml</p>
  
  <pre><code>&lt;multipart-config&gt;
    &lt;!-- 50MB max --&gt;
    &lt;max-file-size&gt;52428800&lt;/max-file-size&gt;
    &lt;max-request-size&gt;52428800&lt;/max-request-size&gt;
    &lt;file-size-threshold&gt;0&lt;/file-size-threshold&gt;
  &lt;/multipart-config&gt;
  </code></pre>
  
  <p>server.xml</p>
  
  <pre><code>&lt;Connector port="443" maxPostSize="67589953" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" sslEnabledProtocols="TLSv1,TLSv1.1,TLSv1.2" useServerCipherSuitesOrder="true" ciphers="TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" server="Web Server" minSpareThreads="25" allowTrace="true" keystoreFile="cert.pfx" keystorePass="" keystoreType="PKCS12" connectionTimeout="100000000" /&gt;
  </code></pre>
  
  <p>Thanks for your help!</p>