We help IT Professionals succeed at work.

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

ukerandi
ukerandi asked
on
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

Comment
Watch Question

Chief Technology Ninja
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:

Hi,


I think you should get in touch with BreezyHR's support. Thing is, you are getting Error 502 is from the server side, you are calling an API and that API is throwing this exception. Unless, you are running / have access to the server, it will be difficult to figure out this one.


Regards,

Chinmay.