Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Post call that takes a string GUID "AA0DB615-D4CB-4466-BC23-0E0083002220"
I am using HTTPWebRequest to send request but I am not sure how to add this along with my Post request. Basically I have not found any method inside the HTTPWebRequest to send a Post that is just a string or a character datatype. Is their anything like request.AddBody

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://exampleapi.com");
                    request.ContentType = "application/json";
                    request.Method = "POST";


request.AddBody ???

What I have tried:

I am not sure how to add the post parameter to the body of the request.
Posted
Updated 2-Apr-20 2:08am

1 solution

You have to call GetRequestStream and write the request body to that stream.
WebRequest.GetRequestStream Method (System.Net) | Microsoft Docs[^]

NB: It might be easier to use the HttpClient class instead of the low-level WebRequest class:
HttpClient Class (System.Net.Http) | Microsoft Docs[^]
Call a Web API From a .NET Client (C#) - ASP.NET 4.x | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900