I have a requirement to encode the file data into base64 encoding and upload the file, This works completely fine if the file size is less than 2-3KB when i try sending relatively big files it throws 403 error(Remote Server returned an error: (403) Forbidden), There is no issue with authentication it is successfully established.
Below is the code snippet I am using to make request
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
I am not sending the file as multipart/formdata as my requirement needs the file data to be encoded, what change should i make to get this working.