对于大文件,Invoke-WebRequest失败

时间:2017-08-30 13:24:08

标签: powershell tomcat

以下问题: 使用下面的power shell脚本只能在war文件大小低于4MB的情况下通过tomcat管理器将.war文件从服务器A传输到服务器B.超过该尺寸的所有内容均以

失败
  

Invoke-WebRequest:底层连接已关闭:发送时发生意外错误。   在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

我在服务器A上通过PowerShell运行的代码是:

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&update=true" -Method PUT -Credential $credential -ContentType 'application/zip' -UseBasicParsing -TimeoutSec 120)

我还使用了帖子How to deploy a war file in Tomcat 7中提到的tomcat8的server.xml和tomcat管理器的web.xml。

如图所示,使用50 MB我是安全的。

\ web应用\经理\ WEB-INF \ web.xml中

<multipart-config>
  <!-- 50MB max -->
  <max-file-size>52428800</max-file-size>
  <max-request-size>52428800</max-request-size>
  <file-size-threshold>0</file-size-threshold>
</multipart-config>

server.xml中

<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" />

感谢您的帮助!

0 个答案:

没有答案