REST - HttpClient - Server, C#, http all ok, https not ok

Markus Freitag 3,786 Reputation points
2023-10-19T18:05:35.91+00:00

https://learn.microsoft.com/en-us/answers/questions/1362696/rest-httpclient-server-c-practical-example

@Lan Huang-MSFT,

Sorry, I can't reproduce your issue. Maybe you could follow SurferOnWww's advice: use Fiddler or equivalent to see what's going on between client and server.

I have found the cause, it is because of the security.

What can be the solution?

It would be great if I could get the server on another PC.

See my link. Do you know a good way, instruction.

How do you solve the authentication? What are the options?

using (var client = new HttpClient())
{
	client.BaseAddress = new Uri("http://localhost:55893/");

	//client.DefaultRequestHeaders.Accept.Clear();
	//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
	//string authorization = $"{""}:{""}";
	//client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "");                   

	//GET Method
	//HttpResponseMessage response = await client.GetAsync("api/valuesGET");

	//http://localhost:55893/Api/ValuesGET
    //string urlParameters = $@"Api/ValuesGET";
	
	//urlParameters = $@"Api/ValuesGET?status=2";
    //http://localhost:55892/api/ValuesGET?status=2

	HttpResponseMessage response = client.GetAsync("Api/valuesGET").Result;

	HttpResponseMessage response2 = await client.GetAsync("Api/valuesGET");


	if (response.IsSuccessStatusCode)
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,418 questions
C#
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.
10,650 questions
{count} votes