Then the only way you’re going to be able to make that request in .NET 6 is to use the obsolete HttpWebRequest. I’ve extracted the PostJsonToUrl API into this helper:
public static class LegacyHttpUtils
{
public static string PostJsonToUrl(string url, object data,
Action<HttpWebRequest> requestFilter = null, Action<HttpWebResponse> responseFilter = null)
{
return SendStringToUrl(WebRequest.CreateHttp(url), method: "POST", requestBody: data.ToJson(), contentType: MimeTypes.Json,
accept: MimeTypes.Json,
requestFilter: requestFilter, responseFilter: responseFilter);
}
public static string SendStringToUrl(HttpWebRequest webReq, string method, string requestBody, string contentType,
string accept, Action<HttpWebRequest> requestFilter, Action<HttpWebResponse> responseFilter)
{
if (method != null)
webReq.Method = method;
if (contentType != null)
webReq.ContentType = contentType;
webReq.Accept = accept;
PclExport.Instance.AddCompression(webReq);
requestFilter?.Invoke(webReq);
if (requestBody != null)
{
using var reqStream = PclExport.Instance.GetRequestStream(webReq);
using var writer = new StreamWriter(reqStream, HttpUtils.UseEncoding);
writer.Write(requestBody);
}
else if (method != null && HttpUtils.HasRequestBody(method))
{
webReq.ContentLength = 0;
}
using var webRes = webReq.GetResponse();
using var stream = webRes.GetResponseStream();
responseFilter?.Invoke((HttpWebResponse)webRes);
return stream.ReadToEnd(HttpUtils.UseEncoding);
}
}