newHelpline: +91-22-26201606 Ext.325/315. +91-22-26201604 Ext.633.
Mobile Seva

How to write Dot Net (C#) Client for accessing IVRS Push Call API?


Note: IVRS Push Call API will be accessible with TLSv1.2 protocol. Kindly upgrade to latest .NET versions for TLSv1.2 support.


Kindly refer the below links for .NET TLS support and upgradation:-


https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls

https://blogs.perficient.com/2016/04/28/tsl-1-2-and-net-support/

Click to download the IVRS Push Call API C#.NET code file(Size:18KB)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;
using System.IO;
using System.Security;
using System.Security.Cryptography.X509Certificates;


namespace ConsoleApplication3

    class Program
    {
        static void Main(string[] args)
        {


            String username = ""
            String password = "";
            String MobileNumbers = "";
            String voiceCode = "";
           

            String postData = "username=" + username + "&password=" + password + "&MobileNo=" + MobileNumbers + "&CallID"+CallID +"&voiceCode=" + voiceCode;//data to post
            String url = "https://services.mgov.gov.in/PushCallAPI/MakePushCall";//url 

            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            request.Method = "POST";

            System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();

            byte[] array = Encoding.ASCII.GetBytes(postData);

            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = array.Length;
            Stream requestStream = request.GetRequestStream();


            requestStream.Write(array, 0, array.Length);
            requestStream.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Console.WriteLine(new StreamReader(response.GetResponseStream()).ReadLine());
            Console.WriteLine(response.StatusCode);
            Console.ReadLine();

        }
        class MyPolicy : ICertificatePolicy
        {
            public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
            {
                return true;
            }
        }
    }
}