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
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.
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.
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 ?
hi @megharajky
did you got any solution for this ?
Hi, I got this long back, but discussion went on another thread too so I posted solution there.
Refer thisâŚ
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
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?
Hi @Mateus_Cruz @megharajky
Specified same headers, Also Iâm passing Authorization as well. But getting response - âError 415 - Unsupported Media Typeâ
Note:
-
Able to upload file in postman
-
Tried passing âapplication/xmlâ and âapplication/jsonâ in body format, didnât worked.
Thanks!
hi! iâm having the same problem. Do you know what was the solution ?