Show / Hide Table of Contents

Method internet.jsonContent(+ 2 overloads)


Overload

Creates an HttpContent for posting an object serialized as JSON. It can be used with functions like System.Net.Http.HttpClient.PostAsync and ExtInternet.Post.

public static JsonContent jsonContent<T>(T x)
Parameters
x  (T)

An object of any type that can be serialized to JSON with a JsonSerializer.

Returns
JsonContent
Exceptions
Exception

Exceptions of System.Net.Http.Json.JsonContent.Create<T>.

Type Parameters
T

Remarks

Just calls System.Net.Http.Json.JsonContent.Create<T>. You can instead call it directly if want to specify media type or JSON serializer parameters.

Examples

var v = new POINT(10, 20);
string s = internet.http.Post("https://httpbin.org/anything", internet.jsonContent(v)).Text();

Overload(next)

Creates an HttpContent for posting a JSON string. It can be used with functions like System.Net.Http.HttpClient.PostAsync and ExtInternet.Post.

public static StringContent jsonContent(string json)
Parameters
json  (string)

JSON string.

Returns
StringContent

Examples

string json = "{ ... }";
string s = internet.http.Post("https://httpbin.org/anything", jsonContent(json)).Text();

Overload(top)

Creates an HttpContent for posting JSON. It can be used with functions like System.Net.Http.HttpClient.PostAsync and ExtInternet.Post.

public static StringContent jsonContent(JsonNode json)
Parameters
json  (JsonNode)
Returns
StringContent