Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
string outputXml = "";
            string url = "https://api.com/endpoint";
            string param = "?username=Jey&Password=Pass123";
            url = url + param;
            
            CookieContainer cookies = new CookieContainer();
            HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;
            string contentType = "pplication/x-www-form-urlencoded";
            System.Net.ServicePointManager.Expect100Continue = false;
            webRequest.Method = "POST";
            webRequest.ContentType = contentType;
            //webRequest.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            webRequest.CookieContainer = cookies;
            StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
            string responseData = responseReader.ReadToEnd();
            responseReader.Close();
            webRequest.GetResponse().Close();

            var parsed = JObject.Parse(responseData);
            string token = parsed.SelectToken("access_token").ToString();


What I have tried:

CookieContainer cookies = new CookieContainer();
Posted
Updated 30-Jul-19 0:03am
Comments
Afzaal Ahmad Zeeshan 30-Jul-19 11:10am    
What does the name suggest?

1 solution

Asking a question is a skill: dumping a lump of code and adding the text "Cookie container means?" doesn't represent a good example of it's use.

Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. So if your code doesn't do that you expect, or does do something you didn't, you need to explain that to us with sufficient context that we understand exactly what you are trying to do, what happened when you did it, what you expected to happen, and what you have tried to either find out why, or fix it.

Without that, all we can do is refer you to the standard documentation: CookieContainer Class (System.Net) | Microsoft Docs[^] which you could have found with a trivial Google.
 
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