c# HttpWebRequest.GetResponse() returned an error: (404) Not Found
c# HttpWebRequest.GetResponse() returned an error: (404) Not Found
我有一个 Asp.net 控制台应用程序,我使用此代码上传文件:
byte[] buffer = memoryStream.ToArray();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/octet-stream";
request.Method = "POST";
request.ContentLength = buffer.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(buffer, 0, buffer.Length);
dataStream.Close();
response = (HttpWebResponse)request.GetResponse();
如果缓冲区大小为 8 MB,则 HttpWebResponse 工作完美,但如果缓冲区大小为 32 MB,则 request.GetResponse() 返回错误:
The remote server returned an error: (404) Not Found.
我想您尝试请求的 url 具有最大请求长度,不允许大长度的请求。
修改应该在目标服务或 url 中。
配置文件修改:
<httpRuntime maxRequestLength="33554432" executionTimeout="300"/>
我有一个 Asp.net 控制台应用程序,我使用此代码上传文件:
byte[] buffer = memoryStream.ToArray();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/octet-stream";
request.Method = "POST";
request.ContentLength = buffer.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(buffer, 0, buffer.Length);
dataStream.Close();
response = (HttpWebResponse)request.GetResponse();
如果缓冲区大小为 8 MB,则 HttpWebResponse 工作完美,但如果缓冲区大小为 32 MB,则 request.GetResponse() 返回错误:
The remote server returned an error: (404) Not Found.
我想您尝试请求的 url 具有最大请求长度,不允许大长度的请求。
修改应该在目标服务或 url 中。 配置文件修改:
<httpRuntime maxRequestLength="33554432" executionTimeout="300"/>