UiPath Http Request Upload file with Multipart form-data

How to Upload files with Form-data via HTTP Request from UiPath Studio. How to Download files that are received from HTTP Request inside of UiPath Studio.

0:20​ cURL example
1:35​ Send the command from POSTMAN
2:50​ Implement the code in C#
4:20​ Run the code
4:50​ Visual Basic code VB.NET
6:20​ New Process on UiPath Studio with Invoke Code
7:20​ Imports Libraries in UiPath Studio
8:30​ Run the Robot to Upload and Download the file

Dim client As HttpClient = New HttpClient()
client.BaseAddress = New Uri(“YOUR URL”)
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue(“application/vnd.openxmlformats-officedocument.wordprocessingml.document”))
Dim byteArray As Byte() = Encoding.ASCII.GetBytes(“username:password”)
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, Convert.ToBase64String(byteArray))Dim byteArray As Byte() = Encoding.ASCII.GetBytes(“username:password”)
// for OAUTH2
client.DefaultRequestHeaders.Add(“authorization”, “Bearer YOUR TOKEN”)
Dim request As MultipartFormDataContent = New MultipartFormDataContent()
request.Add(New StringContent(“tags”), “Bad”)
request.Add(New StringContent(“displayreferencetext”), “true”)
request.Add(New StringContent(“similaritythreshold”), “0.63”)
request.Add(New StreamContent(File.OpenRead(“C:\8A.docx”)), “file”, (New FileInfo(“C:\8A.docx”).Name))
Dim response As HttpResponseMessage = client.PostAsync("", request).Result
Dim strm As Stream = response.Content.ReadAsStreamAsync.Result
Dim doc As Byte()
Dim ms As MemoryStream = New MemoryStream()
doc = ms.ToArray()
File.WriteAllBytes(“C:\rpa\FORDOWNLOAD\rez.docx”, doc)