Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Related to Question at:
- //http://http://groups.google.com/group/dotnetdevelopment/browse_thread/thread/6a3a732e06d8598f
- class NDNC
- {
- static void Main(string[] args)
- {
- // Hit 1: Registered.
- HitNDNC("9999774442");
- // Hit 2: Not Registered.
- HitNDNC("9999988888");
- }
- private static void HitNDNC(string phoneNum)
- {
- bool isRegistered;
- string postData = string.Format("phoneno={0}", phoneNum);
- // Prepare web request...
- try
- {
- String post_response = null;
- ASCIIEncoding encoding = new ASCIIEncoding();
- byte[] data = encoding.GetBytes(postData);
- HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://ndncregistry.gov.in/ndncregistry/saveSearchSub.misc");
- myRequest.Method = "POST";
- myRequest.ContentType = "application/x-www-form-urlencoded";
- myRequest.ContentLength = data.Length;
- using (Stream rqStream = myRequest.GetRequestStream())
- {
- // Send the data.
- rqStream.Write(data, 0, data.Length);
- HttpWebResponse objResponse = (HttpWebResponse)myRequest.GetResponse();
- if (objResponse != null)
- {
- using (StreamReader rnStream = new StreamReader(objResponse.GetResponseStream()))
- {
- post_response = rnStream.ReadToEnd();
- }
- }
- }
- if (!string.IsNullOrEmpty(post_response))
- isRegistered = ParseResponse(post_response);
- else
- // An error occurred.
- Console.WriteLine("An error occurred.");
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- private static bool ParseResponse(string post_response)
- {
- if (post_response.Contains("This Number is Registered in NDNC Registry Database"))
- return true;
- else if (post_response.Contains("This Number is not Registered in NDNC Registry Database"))
- return false;
- else
- {
- //An error occurred. The required page was not found.
- //Find out what the hell happened!
- throw new InvalidOperationException("Oops!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment