HttpClient // WebClient // Is there a way to call Post request without HTTPClient?

Noah Aas 1,210 Reputation points
2024-11-28T18:30:22.8133333+00:00

Hello,

Why is not POST working? Is there another way to make Post request?

When I call all with C# works well. When I call it via CLI/C++ and C#, works not.

  • Newtonsoft.Json
  • System.Net.Http.Formatting What is the correct combination of these files. Where do I get them?
using (HttpClient client = new HttpClient())
{
	client.BaseAddress = new Uri(Address_base);
	client.Timeout = new TimeSpan(0, 0, Timeout);

	string authorization = $"{""}:{""}";
	client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "");

	urlParameters = $@"{workorder_endpoint}";

	string request = JsonConvert.SerializeObject(p, Newtonsoft.Json.Formatting.Indented);
	response = client.PostAsJsonAsync(urlParameters, p).Result;   
}

I try this, unkown error as exception.

using (WebClient wc = new WebClient())
{
	wc.Headers[HttpRequestHeader.ContentType] = "application/json";
	string HtmlResult = wc.UploadString(Cfg.MES.Address_base + urlParameters, request);
}
	
---------------------------
Exception ExecuteIsValidWorkorder = '/server/rest/api/IsWorkorder'
 
The file or assembly “Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed” or a dependency of it was not found. The manifest definition of the assembly found does not match the assembly reference. (Exception from HRESULT: 0x80131040)
---------------------------
OK   
---------------------------
---------------------------
Machinemanager
---------------------------
The file or assembly “System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35” or a dependency of it was not found. The manifest definition of the assembly found does not match the assembly reference. (Exception from HRESULT: 0x80131040)
---------------------------
OK   

---------------------------
Machinemanager
---------------------------
Exception ExecuteIsValidWorkorder = '/server/rest/api/IsWorkorder'
 
Die Datei oder Assembly "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" or a dependency on it was not found. The manifest definition of the assembly found does not match the assembly reference
---------------------------
OK   
---------------------------
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.