I am trying to upload file via invoke code (VB) but getting bad request. Do we have to make any changes to define file content? Below is the code:
Dim fr As System.Net.HttpWebRequest
Dim targetURI As New Uri(strURL)
Dim postStream As Stream
fr = DirectCast(HttpWebRequest.Create(targetURI), System.Net.HttpWebRequest)
Dim webProxy As IWebProxy = New WebProxy(strIpAddressAndPort)
webProxy.Credentials = New NetworkCredential(strProxyUsername, strProxyPassword)
fr.Proxy = webProxy
fr.Headers.Add(“Authorization”, jwtOutput)
fr.Headers.Add(“zapiAccessKey”, “MWExM2QyZTYtYzBlMi0zODI5LWIzMjUtZWNjZDJjMDBkODQ5IDYyMjhlODliYzg4ZjEwMDA2ODMyNWRhNCBVU0VSX0RFRk”)
fr.Method= “POST”
fr.ContentType = “multipart/form-data”
Dim bytes As Byte() = System.Text.Encoding.UTF8.GetBytes(FilePath)
postStream = fr.GetRequestStream()
postStream.Write(bytes,0,bytes.Length)
postStream.Close()
Dim res As HttpWebResponse = DirectCast(fr.GetResponse(), System.Net.HttpWebResponse)
webRes = res
Dim html As String = New StreamReader(res.GetResponseStream()).ReadToEnd()
strHtml = html