Hi guys,
I'm trying to port some code from retrofit2 to refit.
The retrofit version is like this:
@POST("user/me/") @Multipart Observable
If I use multipart with strings in my c# code, the request is different that retrofit2 request.
Also by copy pasting retrofit2 request in postman generates an error.
Bellow can find some screenshots.
Thanks.


Hi @AdrianSTANCULESCU, can you paste your Refit C# code in please that's not working?
Hi @benjaminhowarth1
Here is the code that I have tried:
//declaration method in interface
[Multipart("644e1dd7-2a7f-18fb-b8ed-ed78c3f92c2b")]
[Headers(blabla)]
Task
...
//api call
//login api call
string guidS = "644e1dd7-2a7f-18fb-b8ed-ed78c3f92c2b";
var contentTypeHeader = $"Content-Type: multipart/form-data; boundary={guidS}";
string username = "username";
string password = "password";
string getImageQuality = "quality";
var loginResponse = await myApi.Login(ouDeviceLocationHeader, contentTypeHeader, username, password, getImageQuality);
The problem is that after content-type no parameter is inside quotes, and after each parameter there is no content-length, so the request is dropped by the server.
Thanks.
Hi @benjaminhowarth1
Another issue might be "MyGreatBoundary" according to the documentation:
"A custom boundary can be specified with an optional string parameter to the Multipart attribute. If left empty, this defaults to ----MyGreatBoundary."
The optional string parameter can be only a hardcoded value, so cannot be changed at runtime.
In my manual webrequest I did something like that:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
string guid = Guid.NewGuid().ToString();
request.ContentType = $"multipart/form-data; boundary={guid}";
....
So instead of hardcoded boundary or Multipart attribute, I think can be done easy by generating guid on the fly.
Thanks,
Adrian.
@AdrianSTANCULESCU I am also facing same issue. Are you able to do this with refit?
Hi @ranjanpr
Currently I'm doing this part of code with classic webrequests.
There is a nice fiddler plugin: http://www.chadsowald.com/software/fiddler-extension-request-to-code
where you can see the request directly converted to c# code. So for the moment solved my issues, even the code is not as clean as with refit.
Good luck!
Chad SowaldThis Fiddler extension generates C#, VB, or Python code to duplicate a web request. You simply drag one or more Fiddler sessions into the “Code” tab or use the ‘r2c…’ QuickExec command and the extension will produce appropriate code that you can copy and paste into your… Continue reading
@AdrianSTANCULESCU Thanks for the fiddler extension. I think it is not possible right now with current refit. I did the same HttpWebRequest for multipart form-data.
Hope it gets supported in future versions. One idea could be like in multi-query we use [Query(CollectionFormat.Multi)] similarily we can have [StreamPart(CollectionFormat.Multi)] or something similar. Not sure how much is it possible. If possible we can create a feature request for its support. Also custom boundary seems broken even for single streampart currently like you have mentioned earlier.
Closing due to age. Please try Refit v6 and reopen if still an issue.