首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在HTTPPost请求中发送非常大的字符串数据

在HTTPPost请求中发送非常大的字符串数据
EN

Stack Overflow用户
提问于 2017-09-20 17:49:43
回答 1查看 765关注 0票数 0

我有一个文件数据编码成base64编码和上传文件的要求,这是完全正常的,如果文件大小小于2-3KB当我尝试发送相对较大的文件时抛出403错误(远程服务器返回错误:(403)禁止),没有身份验证的问题,它是成功建立的。

下面是我用来发出请求的代码片段

代码语言:javascript
运行
复制
Public Shared Function PostData() As String
Dim sReturnValue As String = String.Empty
Dim sUrl As String = http://localhost:50562/API/UploadFile/UploadSingleFile
Dim oRequest As HttpWebRequest
Dim oResponse As HttpWebResponse

oRequest = TryCast(WebRequest.Create(sUrl), HttpWebRequest)
oRequest.AllowWriteStreamBuffering = True
oRequest.Method = "POST"
oRequest.ContentType = "text/json"
oRequest.Headers.Add("Accept-Language", "en-us")
If m_bPassKeyInHeader = True Then
    oRequest.Headers.Add("APIKey", m_sAPIKey)
End If
If i_sData IsNot Nothing AndAlso i_sData.Length > 0 Then
    Using oWriter As New StreamWriter(oRequest.GetRequestStream())
        oWriter.Write(i_sData)
    End Using
End If

Try
    oResponse = oRequest.GetResponse()
Catch ex As Exception
End Try

Using oReader As New StreamReader(oResponse.GetResponseStream())
    sReturnValue = oReader.ReadToEnd()
End Using

Return sReturnValue

我没有将文件作为multipart/formdata发送,因为我的需求需要对文件数据进行编码,我应该进行哪些更改才能使其正常工作。

EN

回答 1

Stack Overflow用户

发布于 2017-09-20 18:24:00

尝试在web.config中增加maxRequestLength和maxAllowedContentLength:

代码语言:javascript
运行
复制
  <system.web>
    <httpRuntime targetFramework="4.6.2" maxRequestLength="1048576" />
  </system.web>

..。

代码语言:javascript
运行
复制
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
  </system.webServer>

Which gets priority, maxRequestLength or maxAllowedContentLength?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46318748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档