Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-07-01
6
Medium Priority
?
1,101 Views
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 emailsubdomain.isp.yourcompany.com (HTTP)
HTTP monitor emailsubdomain.isp.yourcompany.com (HTTP)
HTTPS monitor emailsubdomain.isp.yourcompany.comm (HTTPS)
PING monitor emailsubdomain.isp.yourcompany.com (PING)
PORT - IMAPs monitor emailsub.isp.yourcompany.com on IMAP Port 993  

A test sample URL will be like below:
http://emailsubdomain.isp.yourcompany.com/owa/
https://emailsubdomain.isp.yourcompany.com/owa/

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

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"
 
        Try
 
            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("https://subdomain.isp.yourcompany.com/owa/"), 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)
            newStream.Close()
 
        Catch ex As Exception
 
	End Try
 
End Sub

Open in new window

0
Comment
Question by:netimpact
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 19

Expert Comment

by:daveamour
ID: 24784867
You might find the WebRequest class easier to work with:
http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx
 
0
 

Author Comment

by:netimpact
ID: 24794527
daveamour:

Thanks for you reply.

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

When I use this URL https://email.company.com/ I get an error message as
below. But when I use this URL http://gsexdev.blogspot.com/ it seems to be fine.

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

ERROR MESSAGE
==============

{"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()
        Try
            ' Create a request for the URL.         
            Dim request As WebRequest = WebRequest.Create("https://email.isp.company.com/")
            'Dim request As WebRequest = WebRequest.Create("http://gsexdev.blogspot.com/")
 
            ' 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.
            Console.WriteLine(response.StatusDescription)
            ' 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. 
            Console.WriteLine(responseFromServer)
            ' Cleanup the streams and the response.
            reader.Close()
            dataStream.Close()
            response.Close()
 
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
 
    End Sub

Open in new window

0
 
LVL 19

Expert Comment

by:daveamour
ID: 24794540
Are you able to show me the actual https address you are hitting?
0
How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

 

Author Comment

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

Author Comment

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

Accepted Solution

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 (http://www.ecb.europa.eu/stats/exch…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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