How Do I Test HTTP / HTTPS / PORT 993 - IMAPs / is Alive TESTs using .NET / VB / C#

Posted on 2009-07-01
Last Modified: 2012-06-21
I have little monitoring app (Windows Forms - desktop) that pings our mail server
every now and then to acertain that it is alive, that part works ok.

What I now want to do is to test the various services & ports below.
i.e. HTTP / HTTPS / PORT 993 - IMAPs/ is Alive using .NET

These will basically be:

HTTP monitor (HTTP)
HTTP monitor (HTTP)
HTTPS monitor emailsubdomain.isp.yourcompany.comm (HTTPS)
PING monitor (PING)
PORT - IMAPs monitor on IMAP Port 993  

A test sample URL will be like below:

The piece of code I was using for the HTTP is below, but this does not work

I want a function or group of functions that will return TRUE/FALSE for the various
tests above.
Private Sub OnPostInfo()

        Dim strId As String = ""

        Dim strName As String = "domain\firstname.lastname"


            Dim encoding As New ASCIIEncoding()

            Dim postData As String = "userid=" & strId

            postData += ("&username=" & strName)

            Dim data As Byte() = encoding.GetBytes(postData)

            'Prepare web request...

            Dim myRequest As HttpWebRequest = DirectCast(WebRequest.Create(""), HttpWebRequest)

            myRequest.Method = "POST"

            myRequest.ContentType = "application/x-www-form-urlencoded"

            myRequest.ContentLength = data.Length

            Dim newStream As Stream = myRequest.GetRequestStream()

            ' Send the data.

            newStream.Write(data, 0, data.Length)


        Catch ex As Exception


	End Try

End Sub

Open in new window

Question by:netimpact
  • 4
  • 2
LVL 19

Expert Comment

ID: 24784867
You might find the WebRequest class easier to work with:

Author Comment

ID: 24794527

Thanks for you reply.

I am using the attached code snippet from MS$ example.

When I use this URL I get an error message as
below. But when I use this URL it seems to be fine.

Any ideas why and how to fix this? Note that the first one is actually an HTTPs.


{"The remote server returned an error: (400) Bad Request."}
"   at System.Net.HttpWebRequest.GetResponse()    
at WebRequestTest.RequestResponse.RequestingaResponse() in C:\download\WebRequestTest\WebRequestTest\RequestIT.vb:line 16"

 Public Shared Sub RequestingaResponse()


            ' Create a request for the URL.         

            Dim request As WebRequest = WebRequest.Create("")

            'Dim request As WebRequest = WebRequest.Create("")

            ' If required by the server, set the credentials.

            request.Credentials = CredentialCache.DefaultCredentials

            ' Get the response.

            Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

            ' Display the status.


            ' Get the stream containing content returned by the server.

            Dim dataStream As Stream = response.GetResponseStream()

            ' Open the stream using a StreamReader for easy access.

            Dim reader As New StreamReader(dataStream)

            ' Read the content.

            Dim responseFromServer As String = reader.ReadToEnd()

            ' Display the content. 


            ' Cleanup the streams and the response.




        Catch ex As Exception


        End Try

    End Sub

Open in new window

LVL 19

Expert Comment

ID: 24794540
Are you able to show me the actual https address you are hitting?
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.


Author Comment

ID: 24795026
Its our OWA address. Is there a way I can send this to you privately or hide it from general view?

Author Comment

ID: 24795411
How do I add a User Agent to that code? That might work.

Accepted Solution

netimpact earned 0 total points
ID: 24798185
Ok, I found another solution that worked using Webclient and User Agent.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Calling web service and its methods dynamically 2 42
Not showing JavaScript in the list 5 40
Help with LINQ and XML 10 27
Help with AsEnumerable(), LINQ 4 22
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: (…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now