0

This is GSTN Portal API
Very strange thing happens to me this API works from 11:AM to 8:PM after 8:PM it stop working and there is no any response when executing this API when I enter short username in request like demousr then its working but when I enter more then 7 digits in username then its not working at all and same is working in day time perfectly.

Anyone please help me as all I have tried without luck.

Please note this API is working in postman fine.

public static AuthenticationResponse GetAuthenticationToken(string captcha)
{

    AuthenticationResponse result = null;

    try
    {
        AuthenticationRequest authrequest = new AuthenticationRequest();

        authrequest.username = "demouser";
        authrequest.password = "demopass";
        authrequest.captcha = captcha;
        authrequest.type = "username";

        Uri requestUri = new Uri("https://services.gst.gov.in/services/authenticate");

        using (HttpClientHandler handler = new HttpClientHandler())
        {
            handler.AllowAutoRedirect = true;
            handler.UseCookies = true;
            handler.CookieContainer = cookies;

            using (HttpClient httpclient = new HttpClient(handler))
            {
                httpclient.DefaultRequestHeaders.Add("Accept", "application/json, text/plain, */*");

                httpclient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");

                httpclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                httpclient.DefaultRequestHeaders.Add("Referer", "https://services.gst.gov.in/services/login");
                httpclient.DefaultRequestHeaders.Add("Origin", "https://services.gst.gov.in");
                httpclient.DefaultRequestHeaders.Add("Host", "services.gst.gov.in");

                httpclient.DefaultRequestHeaders.Add("Connection", "keep-alive");
                //httpclient.DefaultRequestHeaders.Add("Keep-Alive", false);
                //httpclient.Timeout = new TimeSpan(0, 0, 60);

                //httpclient.DefaultRequestHeaders.Add("Content-Type", "application/json;charset=UTF-8");
                httpclient.DefaultRequestHeaders.Add("Accept-Language", "en-US,en;q=0.8");

                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                using (HttpResponseMessage response = httpclient.PostAsJsonAsync(requestUri, authrequest).Result)
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        cookies = ReadCookies(response);

                        result = response.Content.ReadAsAsync<AuthenticationResponse>().Result;                               
                    }
                }
            }
        }
    }
    catch (Exception)
    {

        throw;
    }
    

    return result;
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

If it is working in Postman, do not worry, you have a solution. Just go back to the postman and click on "</>" on the right-hand top side of the screen and you will get a working C# code for your web request.