Avatar of ukerandi
ukerandi
Flag for United Kingdom of Great Britain and Northern Ireland asked on

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

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;


            }

        }

Open in new window

ASP.NET.NET ProgrammingC#JSON

Avatar of undefined
Last Comment
Chinmay Patel

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Chinmay Patel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61