dimanche 2 septembre 2018

How to overcome from 503 Server unavailable error?

I am doing an http request to the unknown server. When i make request from browser then it works like a charm but whenever i make the same request from my application then i get 503 Server unavailable.

I searched for this error and found that this is caused due to server temporary unavailable and another answered as the server believe that this call is made from a bot application.

I made same kind of request to the same server and there is only a small change in the uri. All previous calls are working except this one.

private static Root_BoardingStationList Request_BoardingStation(string uri, string auth,string greq, string sp_csr)
    {      
        Root_BoardingStationList rootBoaringStationEnquiry = null;
        string captchaImageURL = string.Empty;
        string html = string.Empty;
        try
        {
            var request = (HttpWebRequest)WebRequest.Create(uri);
            request.Referer = "https://www.irctc.co.in/nget/train-list";
            request.Headers.Set("Authorization", "Bearer " + login_authorization_bearer);
            request.Headers.Set("greq", greq);
            request.Headers.Set("spa-csrf-token", sp_csr);
            request.Proxy = null;
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.None;
            request.CookieContainer = new CookieContainer();
            request.Method = method;
            request.ContentType = contentType;
            request.KeepAlive = true;
            request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
            request.Connection = "keepalive";                

            using (var response_ = (HttpWebResponse)request.GetResponse())
            {
                var responseString = new StreamReader(response_.GetResponseStream()).ReadToEnd();
            }                
        }
        catch (WebException ex)
        {
            ExceptionLog.HandleException(ex);
            using (var sr = new StreamReader(ex.Response.GetResponseStream()))
                html = sr.ReadToEnd();

        }
        return rootBoaringStationEnquiry;
    } 

Please check and help.

enter image description here




Aucun commentaire:

Enregistrer un commentaire