How to send a Body type "Form Data" using POST in a HTTP Request

hello I have a problem I need to send some parameters to an http request, but the parameters must be of the form-data type, I have not managed to find out how to send the same, I know that in the activity comes the option to send a string, but I do not achieve know what is the format of it

1 Like

If you are referring to the Content-Type parameter, you can specify it in the Headers property of the HTTP request activity:
Name: Content-Type, Direction: In, Type: String, Value: "multipart/form-data"

If you want to send a file with the request, you can pass the filepath to the Attachments property.

6 Likes

@Mateus_Cruz

This helped, thanks lot :slight_smile:

Meg

Hi @Mateus_Cruz
If i have some key-value text fields instead of files then how to set them inside http request?
Thanks.

Have you tried using the Parameters property? It gives you the key-value format that you mentioned.

Also, how are you doing the request in another tool? If you are specifying a JSON string in the body of the request, then it might be simpler to just do the same and pass that string to the Body property.

1 Like

There is some solution to this? I’m having same problem.

Trying to send one ‘application/pdf’ and one ‘text/plain’ into the body so this is and obvious multipart/form-data problem

I don’t know how to fill uipath HTTP Request activity properties to find a good HTTP Status 200

I’ve thought maybe putting in headers the content-type = multipart/form-data and then using parameters to send both, file and text buth the text parameter called “example” cannot be recognized. the request throws me an HTTP Status 400 - Required request part ‘example’ is not present

Hi
i want to pass form-data in http request how where i have to give this information in that activity ?

1 Like

hi @megharajky

did you got any solution for this ?

1 Like

Hi, I got this long back, but discussion went on another thread too so I posted solution there.
Refer this…

2 Likes

Hello Kalyan,
In this video, I use multipart/form-data:

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

Blockquote
Dim client As HttpClient = New HttpClient()
client.BaseAddress = New Uri(“YOUR URL”)
client.DefaultRequestHeaders.Accept.Clear()
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue(“application/vnd.openxmlformats-officedocument.wordprocessingml.document”))
// for BASIC AUTH
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()
strm.CopyTo(ms)
doc = ms.ToArray()
File.WriteAllBytes(“C:\rpa\FORDOWNLOAD\rez.docx”, doc)

Thanks,
Cristian Negulescu

1 Like

I found the video a little hard to follow and seemed to be more about downloading files than uploading. It also wasn’t clear what I need to change in the code too work with my use case

This is the procedure. You need software developer skills. Please watch again the first 3 minutes of the movie and then try all your steps in your case from Postman. After everything is working in Postman then jump to Visual Studio and build code, Last step will be UiPath.
Thanks,
Cristian

I’m not really a software developer, I’m trying to understand this procedure! would be preferable if the UiPath activity would do this!

do I need to specify here what file type I am uploading

apirequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/vnd.openxmlformats-officedocument.wordprocessingml.document”));

And how do I know what syntax to use?

https://www.ibm.com/docs/en/wkc/cloud?topic=catalog-previews