Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to consume a REST service from another company. When I use the link in the browser it works fine. However I get the 401 error when accessing from code. What am I doing wrong? Do I need to add something to the web.config of the web app?
C#
string URL = @"https://hdapps-qa.homedepot.com/MYTHDPassport/rs/identity/isSessionValid?thdsso=TEST&callingProgram=PSC&Submit=Submit";
            HttpWebRequest req = WebRequest.Create(URL)
                                 as HttpWebRequest;
            string result = null;
            req.Method = "GET";
            req.UseDefaultCredentials = true;
            req.PreAuthenticate = false;
            req.Credentials = CredentialCache.DefaultCredentials;
            using (HttpWebResponse resp = req.GetResponse()
                                          as HttpWebResponse)
            {
                StreamReader reader =
                    new StreamReader(resp.GetResponseStream());
                result = reader.ReadToEnd();
            }
Posted
Updated 3-Dec-13 10:57am
v2

1 solution

Figured it out. The REST Service is returning a response code of 401 if the session is not valid. So I am catching that exception and handling it. Thanks.
 
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