我有一个文件数据编码成base64编码和上传文件的要求,这是完全正常的,如果文件大小小于2-3KB当我尝试发送相对较大的文件时抛出403错误(远程服务器返回错误:(403)禁止),没有身份验证的问题,它是成功建立的。
下面是我用来发出请求的代码片段
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发送,因为我的需求需要对文件数据进行编码,我应该进行哪些更改才能使其正常工作。
发布于 2017-09-20 18:24:00
尝试在web.config中增加maxRequestLength和maxAllowedContentLength:
<system.web>
<httpRuntime targetFramework="4.6.2" maxRequestLength="1048576" />
</system.web>..。
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>Which gets priority, maxRequestLength or maxAllowedContentLength?
https://stackoverflow.com/questions/46318748
复制相似问题