I am trying to post using Refit and keep getting a 500 error. The Object that I am posting if I JsonConvert.SerializeObject(model) looks fine but when I pass the model into my Refit Interface I get the following: a 275 before and a 0 after the json
275
{
all my model properties
}
0
Heres my Refit Interface:
[Post("/api/Url/{id})]
Task<HttpResponseMessage> PostModel([Body] Model model, string id);
See Attachments
By default, Refit uses the global JSON.NET JsonSettings, so if you've modified them in any way, it could be the cause.
Otherwise we'd need a fair bit more information to help with this - can you create a small repro project? What sort of environment is this happening in?
I haven't changed any of the JsonSettings. It is happening in Core 2.0 with Angular 4.
You'll see Transfer-Encoding : chunked if you look at the raw message. I guess your server can't handle chunked messages. ( probably .net 4 web api 2+)
I am running in to the following situation. I have a Web API 2 (framework 4.6.) application that i wrote a .netstandard1.4 consuming client library for.
If i grab the newest nuget version 4.0.1 from nuget.org and run that in a .netcoreapp2.0 console application Post does not work. If i build the package from the source code itself (4.0.2-build.43) it works again. but the strange thing is i can't really find any code changes. I would expect ret.Headers.TransferEncodingChunked = true; some where here
I am having the exact same issue in .netcoreapp2.0 with refit 4.0.1, on post methods i get the same result as the OP
Same issue here with Refit version 4.0.1 using .NET Core 2.0.
Can either of you make a repro sample I can test with?
@jordanpowell88 You have to explicitly set Content-Length in your HttpClientHandler if the destination server does not support chunked transfers. I recently had to deal with some ancient piece of crap API leading me towards this issue. @paulcbetts I guess this should be handled by the user because streams ?
public sealed class HackHackHack: HttpClientHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Content != null)
{
var content = await request.Content.ReadAsStringAsync().ConfigureAwait(false);
request.Content = new StringContent(content, Encoding.UTF8, "application/json");
}
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
}
}
If the issue is related to the missing Content-Length header, you can fix it using version 4.1.0.
There is a chance that I have something similar / related so goin to post it here:
In my case API is waiting something like:
{
"auth": {
"time": "2018-02-02 21:59:00",
"sign": "**********" // result of md5(time + secret)
},
"payload": {...} // actual request
}
I wish interface only required from user is to give payload and whole auth block to be calculated / prepended on the flight before sending request
is it possible with current implementation?
@mac2000 that's not possible today. I would suggest using a wrapper class to implement the functionality you need.
Yep seems like a trust, other way me be to mess around with http client handler by wrapping and replacing request content but it looks ugly. Thank you in advice
When will this be fixed?
Closing due to age. Please try Refit v6 and reopen if still an issue.
Most helpful comment
You'll see Transfer-Encoding : chunked if you look at the raw message. I guess your server can't handle chunked messages. ( probably .net 4 web api 2+)