Skip to content

Commit

Permalink
Merge pull request #44 from SameerOmar/master
Browse files Browse the repository at this point in the history
Fixing zero length content when sending requests without body
  • Loading branch information
acupofjose authored Jul 9, 2022
2 parents 483580b + ed562dd commit a130779
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Postgrest/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Newtonsoft.Json;
using Postgrest.Responses;
using System.Runtime.CompilerServices;
using Newtonsoft.Json.Linq;
using Postgrest.Extensions;

[assembly: InternalsVisibleTo("PostgrestTests")]
Expand Down Expand Up @@ -82,8 +83,13 @@ public static async Task<BaseResponse> MakeRequest(

if (data != null && method != HttpMethod.Get)
{
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(data, serializerSettings),
Encoding.UTF8, "application/json");
var stringContent = JsonConvert.SerializeObject(data, serializerSettings);

if (!string.IsNullOrWhiteSpace(stringContent) && JToken.Parse(stringContent).HasValues)
{
requestMessage.Content = new StringContent(stringContent,
Encoding.UTF8, "application/json");
}
}

if (headers != null)
Expand Down

0 comments on commit a130779

Please sign in to comment.