Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Paymon Khamooshi committed Jan 15, 2024
1 parent 9f494dc commit 0551141
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Olive/-Extensions/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,22 @@ public static Task<string> PostJson(this Uri @this, object data)
=> @this.PostJson(data, customiseClient: null);

/// <summary>
/// Posts the specified object as JSON data to this URL.
/// Posts the specified object as JSON data to this URL. Your server-side web api should take one parameter, with [FromBody] attribute.
/// </summary>
public static Task<string> PostJson(this Uri @this, object data, Action<HttpClient> customiseClient = null)
{
return PostJson(@this, JsonSerializer.Serialize(data), customiseClient);
}

/// <summary>
/// Posts the specified JSON text to this URL. Your server-side web api should take one parameter, with [FromBody] attribute.
/// </summary>
public static async Task<string> PostJson(this Uri @this, object data, Action<HttpClient> customiseClient = null)
public static async Task<string> PostJson(this Uri @this, string json, Action<HttpClient> customiseClient = null)
{
using var client = new HttpClient();
customiseClient?.Invoke(client);

var @string = JsonSerializer.Serialize(data);
var requestContent = new StringContent(@string, Encoding.UTF8, "application/json");
var requestContent = new StringContent(json, Encoding.UTF8, "application/json");

var response = await client.PostAsync(@this, requestContent);

Expand Down
2 changes: 1 addition & 1 deletion Olive/Olive.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.1.359.0</Version>
<Version>2.1.360.0</Version>
<OutputType>Library</OutputType>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down

0 comments on commit 0551141

Please sign in to comment.