Hi Everyone,
Please help me out ,How to call Json Rest API in C# through API KEY with Post method?
Thanks in advance!!
Hi Everyone,
Please help me out ,How to call Json Rest API in C# through API KEY with Post method?
Thanks in advance!!
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sachin SinghPosted Jun 7, 2021, 8:14 PM
Gurpreet AroraPosted Jun 7, 2021, 6:14 PM
string strUrl = // pass the path of api
WebRequest requestObjPost = WebRequest.Create(strUrl);
requestObjPost.Method = "POST";
requestObjPost.ContentType = "application/json";
string postdata =. "{\"title\": \"data\",}". // whatever data you want to post pass the entities
using (var streamWriter = new StreamWriter(requestObjPost.GetRequestStream()))
{
streamWriter.Write(postdata);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)requestObjPost.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result2 = streamReader.ReadToEnd();
}
}