How to add the below headers to httpclient .NET 4.7.2. and How to add this json to the body of a PUT request?
I did not create the server I put test to sensor the data its a third party plugin. Using the header setting and the Json body in Postman client app with the Postman Agent app this works. But it does not work when trying through C# I am getting Error: 400 Bad request.
Cache-Control -> no-cache
Postman-Token -> <calculated when request is sent>
Content-Type  -> application/json
Content-Length -> <calculated when request is sent>
Host -> <calculated when request is sent>
User-Agent -> Postman Runtime/7.29.0
Accept -> */*
Accept-Encoding -> gzip,deflate,br
Json:
{
    "objectPath": "/TestData1/TestData2/_C++TestData3/TestData6.TestData8:TestData15",
    "functionName": "Test_FuncCall",
    "generateTransaction": true
}
Code:
static void Main(string[] args)
{
    using (var client = new HttpClient())
    {
        JObject data = JObject.Parse(File.ReadAllText(@"D:\data.txt"));
        client.BaseAddress = new Uri("http://127.0.0.1:5555/");
        var content = new StringContent(data.ToString(), Encoding.UTF8, "application/json");
        var response = client.PutAsync("test1/test2/test3", content).Result;
        if (response.IsSuccessStatusCode)
        {
            Console.Write("Success");
        }
        else
            Console.Write("Error");
    }
    Console.ReadKey();
}
One step after break point then hover over response:
{StatusCode: 400, ReasonPhrase: '', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Access-Control-Allow-Origin: *
  Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS
  Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
  Access-Control-Max-Age: 600
  keep-alive: timeout=15.000000
  Content-Length: 67
  Content-Type: application/json
}}
This Works:
Call:
  TestServer yyy = new TestServer();
            JObject data2 = JObject.Parse(File.ReadAllText(@"D:\data.txt"));
            yyy.SendRequest("http://127.0.0.1:5555/test1/test2/test3", "PUT", data2.ToString(), false);
function:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestURIString);
request.UserAgent = "Test App";
request.Method = method;
if (body != "")
{
     p_CurrentAPIRequest = body;
    request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);
}
else
    request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
allDone.WaitOne();





JSONstructure in yourcontentvariable? You can add your headers with your request like this:client.DefaultRequestHeaders.Add("Cache-Control", "no-cache");and so on.reponse?