troubleshooting Question

WebException: The remote server returned an error: (502) Bad Gateway. This exception was originally thrown at this call stack

Avatar of ukerandi
ukerandiFlag for United Kingdom of Great Britain and Northern Ireland asked on
.NET ProgrammingC#ASP.NETJSON
1 Comment1 Solution224 ViewsLast Modified:
Hi'im getting following Error message most of time.After run the program it's working fine.sometime it's again comming.Any idea much appriciated


Error

WebException: The remote server returned an error: (502) Bad Gateway.
This exception was originally thrown at this call stack:
      System.Net.HttpWebRequest.GetResponse()
    BreezyHRapp_v2.Admin.connectAPI.getAccessToken() in connectAPI.cs
    BreezyHRapp_v2.Candidate.candidateRecords.candidateDetails(string, string) in candidateRecords.cs
      System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
      System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
      System.Runtime.CompilerServices.TaskAwaiter<TResult>.GetResult()
    BreezyHRapp_v2.Candidate.candidateClient.candidateDetails(string[]) in candidateClient.cs



string url = "/company/"+ companyID +"/position/"+ positionID + "/candidates";
            var request = new RestRequest(url, Method.GET);


            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("authorization", connectAPI.getAccessToken());



public static string getAccessToken()
        {
            _restClient = new restClient();
            string path = _restClient.SigninUrl;
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(path);
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {

                
                string json = JsonConvert.SerializeObject(_restClient, Formatting.Indented);


                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
                var result = "";
                var tempAceessToken = "";
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    result = streamReader.ReadToEnd();
                }
                var varRestClient = JsonConvert.DeserializeObject<restClient>(result);
                tempAceessToken = varRestClient.access_token;
                return varRestClient.access_token;


            }

        }
ASKER CERTIFIED SOLUTION
Chinmay Patel
Chief Technology Ninja
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros