Closed natn2323 closed 5 years ago
@natn2323 Unfortunately, we don't have any easy way to introduce that at the moment.
There is a way to do it, but would need to override the HttpClient class and need to create a new IApiRequest object.
Let me know if you would like me to provide you an example of this.
@djmnz Thank you for the reply. Yes, please provide an example of how to override the HttpClient class and how to create the new IApiRequest object.
@natn2323 I created a sample in a feature branch
Most of the code is on the "Client" folder.
You can pretty much copy the whole folder to your solution and see if it works.
The usage is on the SampleClient.cs:
var config =
new RestConfiguration()
.WithBaseUrl("http://localhost:8080/")
.UseJsonResponseDeserialiser()
.UsingMultipartApiClient();
config.RequestDefaults.TimeoutInSeconds = 90;
config.Post("/")
.WithMultipart(r => r.Add(new StringContent("value"), "key"))
.Response()
.ReturnsStatus(HttpStatusCode.OK);
The main bits are: Set the special client
.UsingMultipartApiClient();
Modify your content
.WithMultipart(r => r.Add(new StringContent("value"), "key"))
To be completely honest, I haven't tested the code, this is more to give you a head-start. Let me know if you have any issues.
@natn2323 I decided to have a go on the sample and found that it wouldn't have worked. :)
I fixed a bug on Restfluencing.Core to allow to example to work properly.
Make sure you use the version 1.0.1
https://www.nuget.org/packages/RestFluencing/1.0.1.35
Let me know how it goes.
I updated to 1.0.1.
I modified the code within SampleClient.cs and tested the MultipartForm POST request against my own endpoint. Works like a charm! Please commit--I'd love to start implementing this everywhere in my project!
I'm very grateful for your assistance, @djmnz!
Hi @djmnz,
Any update on when this feature might be available in the master branch?
I will try to do this weekend sorry.
You can still use the code provided as a start, all you may need to do is change namespaces .
From: Nathan Nguyen notifications@github.com Sent: Tuesday, May 21, 2019 3:35:29 AM To: djmnz/RestFluencing Cc: Douglas Jimenez; Mention Subject: Re: [djmnz/RestFluencing] Using WithBody function with MultipartFormDataContent object (#13)
Hi @djmnzhttps://github.com/djmnz,
Any update on when this feature might be available in the master branch?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/djmnz/RestFluencing/issues/13?email_source=notifications&email_token=ABH7TB3XL6D3NPWVDQDXVDTPWLAMDA5CNFSM4HIIQ6VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVZHBDI#issuecomment-494039181, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABH7TBZDS4TQ7ONIBGYBZLDPWLAMDANCNFSM4HIIQ6VA.
I tried changing the namespaces, but was unsuccessful in being able to call the new UsingMultipartApiClient
code.
hi @natn2323 sorry for taking so long to come back to you.
I added the support for multipart content requests in the core library. Version 1.1.0.43
You should be able to use the namespace RestFluencing.Client.MultipartApiClient
and the extensions are the same as in the original example.
Thank you, @djmnz!
AFAIK, there isn't a wait to use
WithBody(string)
with a data type other than string. I'm trying to send an un-serialized MultipartFormDataContent object. Currently, is this possible to do with RestFluencing in general? If not, is this feature going to be implemented?