调用接口上传文件遇到http状态404失败

当上传一个超过30M的文件时,服务器会重定向至404.13页面,报错如下:

HTTP Error 404.13 - Not Found

The request filtering module is configured to deny a request that exceeds the request content length.

这是由于服务器限制了所能上传文件的最大值。其值在configuration/system.webServer/security/requestFiltering/[email protected] setting in the applicationhost.config or web.config file. 中定义。

查看C:\Windows\System32\inetsrv\config目录下的applicationhost.config,可以在system.webServer/security/requestFiltering/中找到requestLimits设置项,若没有,则可以自行添加如下:(这里maxAllowedContentLength的单位为bytes。)

<system.webServer>
   <security>
       <requestFiltering>
              <requestLimits maxAllowedContentLength="40000000" />
       </requestFiltering>
   <security>
<system.webServer>

也可以使用命令行模式修改applicationhost.config为:

%windir%\system32\inetsrv\appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:40000000

经过这个设置后,服务器对上传文件的大小限制将变为40000000bytes了。当然,这个设置是服务器级别的,如果你想在某个站点或者某个应用上限制大小,也可以通过以相同方式进行设置,只不过这次设置的是站点内的Web.config。

但是你要进行此项修改,要确保applicationhost.config中对该项修改的权限已经放开。可通过如下设置进行更改:

modify the overrideModeDefault from "Deny" to "Allow" like so:

<sectionGroup name="system.webServer">
     <section name="requestFiltering" overrideModeDefault="Allow" />
</sectionGroup>

确认修改过applicationhost.config中上述设置以后,再进行如下设置。

找到应用的Web.config,按上述进行修改:

<system.webServer>
   <security>
       <requestFiltering>
              <requestLimits maxAllowedContentLength="40000000" />
       </requestFiltering>
   <security>
<system.webServer>

或者你也可以通过命令行的形式:

%windir%\system32\inetsrv\appcmd set config "Default Web Site/<your app>" -section:requestFiltering -requestLimits.maxAllowedContentLength:40000000

这样,你就能针对某个站点的某个应用进行设置。

但是开发人员是在Web.Config中进行了如下设置:

<system.web>

<httpRuntime maxRequestLength="40960" appRequestQueueLimit="100" useFullyQualifiedRedirectUrl="true" executionTimeout="120" />

</system.web>

这里的maxRequestLength据MSDN介绍:Gets or sets the maximum request size. The maximum request size in kilobytes. The default size is 4096 KB (4 MB).

The MaxRequestLength property specifies the limit for the buffering threshold of the input stream. For example, this limit can be used to prevent denial of service attacks(拒绝服务攻击) that are caused by users who post large files to the server.

The value assigned to this property should be greater or equal to value assigned to the RequestLengthDiskThreshold property.

但是开发人员的这个设置好像是不起作用的。他们在这里,限制最大请求长度为40MB,超时为120s。

下次再看一下具体这个设置是用来做什么的。

-------------------------

现在明白了。这个是用来设置单个请求的最大长度。比如EmailTicket中若设置maxRequestLength为30M,maxAllowedContentLength为40M,

然后在Reply Email时,选择了一个35M的附件,在点击Save as Draft的时候,这个请求的长度大概会有35M,这个已经超过了maxRequestLength。此时请求就会报错了,结果是黄页:

Server Error in ‘/emailticket‘ Application.


Maximum request length exceeded.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.Web.HttpException: Maximum request length exceeded.

所以,最好是maxRequestLength和maxAllowedContentLength设置为一致的值。

原文地址:https://www.cnblogs.com/longtimetxl/p/11130969.html

时间: 2024-08-08 12:00:33

调用接口上传文件遇到http状态404失败的相关文章

使用python或robotframework调multipart/form-data接口上传文件

这几天调一个multipart/form-data类型的接口,遇到点小阻碍.之前同事有使用urllib库写了个类似的方法实现,比较长,想要改的时候发现不太好使.在网上查找发现用requests库做这个更强大.下面具体介绍一下python-requests及robotframework-RequestsLibrary实现multipart/form-data接口上传文件.1.从fiddler查看接口长这样:Header: WebForms: 2.python-requests实现 #!/usr/b

Jmeter接口上传文件

一.使用抓包软件抓取该接口,查看参数(图例使用的是charles) 可以看到上传文件的参数名是file1 二.把抓取到的普通参数都放在参数这一栏里,如图所示,不要在意马赛克 三.参数名称写在如图所示的位置,就是传文件的参数,文件名称是文件的绝对路径,MIME类型注意跟文件类型匹配,这样就可以啦,完成啦 原文地址:https://www.cnblogs.com/chongzi1990/p/11643664.html

requests通过接口上传文件

如何利用requests上传文件的操作: 抓包发现post请求需要传递参数如下: 代码实现如下:需要带上cookies信息,files需要传递文件名称,传递文件的路径以二进制方式传递,文件的格式. import requests url = "http://admin.cdnzutuan.cn/api/a/upload/uploadappbanner" files = { "file":("蓝天白云.jpg",open(r"D:\ico

webservice(axis)接口上传文件附件 及 用zlib解压缩

webservice传文件,我平时用到的webservice框架也就是Axis和CXF,这两种框架都可以用DataHandler进行文件的传输,这种的传的是文件的内容,不会有文件名称,类型,所以这些得自己在接口中加字段:还有一种方式就是将文件转化成字节数组,再用Base64将字节数组编码成字符串类型放入接口字段中进行传输,接受的一方先解码然后存文件. 目前用到的就是后一种,无论前一种还是后一种,两种方式传输的文件都不能太大,前一种具体能传多大不太清楚,后一种十几兆或者二十多兆还是可以传的,只是传

C# 使用HttpWebRequest通过PHP接口 上传文件

1:上传文件实例 public void UploadXMLLog(string xmlpath)        {            NameValueCollection nvc = new NameValueCollection();            CookieContainer cookies = new CookieContainer();            nvc.Add("", “”);            ......            strin

C#post调用接口并上传文件

/// <summary> /// C#调用接口上传json数据,并且带文件上传 /// </summary> /// <param name="url">接口地址</param> /// <param name="filePath">文件路径</param> /// <returns></returns> public string RequestPost(string

服务器上传文件出现500错误,但是其他不涉及文件的接口均正常

出现的情景描述: 1.有用户报告说注册无法成功,经过前端的盘查发现实在注册的时候必须调用的上传文件的接口A抛出500错误,但不是每次都抛出不过有很大几率抛出500. 2.A接口接受5个参数和一个文件multi类型,至传递前5个参数能够请求到代码,但是传入文件之后不是500错误就是很长时间超时. 3.重启nginx无效,问题依旧.重启fpm无效,问题依旧. 4.机器很久没有启动过了top显示内存占用较高于是重启机器.重启机器问题消失,A接口正常工作,15分钟后再次出现问题且症状依旧. 5.ngin

Hessian学习总结(二)——使用hessian上传文件

hessian较早版本通过 byte[] 进行文件传输:4.0之后支持 InputStream 作为参数或返回值进行传输. 注意:hessian会读取整个文件,如果文件过大,会导致JVM内存溢出.可以通过控制上传文件的大小,设置合理的JVM参数,以及采用随机读取方式来解决. 一.创建Hessian服务端 创建一个FileUploader Web项目作为文件上传的服务端,如下图所示: 1. 1.创建文件上传服务接口FileUploadServiceI FileUploadServiceI接口代码如

JAVA代码实现上传文件至文件服务器(远程服务器、非项目当前所在服务器)

步骤一:添加依赖 <!--sftp文件上传--> <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <version>0.1.54</version> </dependency> 步骤二:编写工具类 package com.example.vue.vuedemo; import com.jcraft.js