How to submit http form using C# in DOTNET CORE
Dotnet core support
var s = "some html / html form";
HttpContext.Response.WriteAsync(s.ToString());
Find refrence :
https://gist.github.com/priore/7163408
Is there an equivalent to "HttpContext.Response.Write" in Asp.Net Core 2?
Submit form using HttpClient in C#
HttpClient.PostAsync
return a Task<HttpResponseMessage>
so normally it would need to be awaited. As you are using it in main method you would have to get the result from the task
var response = client.PostAsync(uri, formContent).GetAwaiter().GetResult();
Or the simpler
var response = client.PostAsync(uri, formContent).Result;
In both cases response would be an instance of HttpResponseMessage
. You can inspect that instance for HTTP status and the content of the response.
If using .net core you can even use an async Main method like
static async Task Main(string[] args) {
//..code removed for brevity
var response = await client.PostAsync(uri, formContent);
var content = await response.Content.ReadAsStringAsync();
//...
}
Related Topics
System.Speech in Mono on Linux
Close a Messagebox After Several Seconds
Why Are Unsigned Int's Not Cls Compliant
Access to Modified Closure (2)
C# Dictionary - One Key, Many Values
If a Folder Does Not Exist, Create It
Operator Overloading with C# Extension Methods
How to Cast from Parent Class to Child Class
Ide's for C# Development on Linux
Extension Methods Must Be Defined in a Non-Generic Static Class
Generic Constraints, Where T:Struct and Where T:Class
Better Way to Check If a Path Is a File or a Directory