ASP.NET Example: checking domain availability

From: feedback@webdivisor.com
Date: Thu Dec 04 2003 - 16:59:42 EST


Hello Everyone:

      Since you all have helped me very much on getting my ASP.NET page to work with the OpenSRS system. I have included the asp.net/vb.net code below that I am using to communicate with the opensrs system. Feel free to use it and let me know if you have any questions... =)

Public Class OpenSRS_XMLPOST
   Public Const URL_BASE = "https://horizon.opensrs.net:55443"
   Public Const RSP_USERNAME As String = "your_username_here"
   Public Const PRIVATE_KEY = "your_private_key_here"

   Public Function sendPost(ByVal str As String)
   Dim myHttpWebRequest As New System.Net.WebClient
      myHttpWebRequest.Headers.Add("Content-Type", "text/xml")
      myHttpWebRequest.Headers.Add("X-Username", RSP_USERNAME)
      myHttpWebRequest.Headers.Add("X-Signature", cMD5(cMD5(str & PRIVATE_KEY) & PRIVATE_KEY))

   Dim sendData As Byte() = System.Text.Encoding.UTF8.GetBytes(str)
   Dim myHttpResponse As Byte() = myHttpWebRequest.UploadData(URL_BASE, "POST", sendData)
      Return System.Text.Encoding.ASCII.GetString(myHttpResponse)
   End Function

'Used to convert to MD5
Public Function cMD5(ByVal str As String) As String
'Must have Imports System.Web.Security in General Declarations
   Dim Hash As String = FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5")
   Return Hash.ToLower
End Function
End Class

Sub checkavailability_click( s as object, e as eventargs)

Dim mypost As New OpenSRS_XMLPOST
Dim RESPONSE_TEXT
Dim responsetext

   response_text = "<?xml version='1.0' encoding='UTF-8' standalone='no' ?><!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'><OPS_envelope><header><version>0.9</version></header><body><data_block><dt_assoc><item key='protocol'>XCP</item><item key='action'>LOOKUP</item><item key='object'>DOMAIN</item><item key='attributes'><dt_assoc><item key='domain'>" & txtdomainname.text & "</item></dt_assoc></item></dt_assoc></data_block></body></OPS_envelope>"
   responsetext = mypost.sendPost(RESPONSE_TEXT)
      lbldomaincom.text = txtdomainname.text & ".com"
   If InStr(responsetext, "210") > 0 Then
      lbldomaincom2.text = "<span style='width: 109'>Available!</span><span style='width: 106'>$10/year</span><a href='' class='standardlink'>Register Now</a>"
   Else
      lbldomaincom2.text = "<span style='width: 109'>Unavailable!</span><span style='width: 106'>N/A</span><a href='' class='standardlink'>View WhoIS</a>"
   End If

End If
End Sub

Thanks
Your friends @ WebDivisor



This archive was generated by hypermail 2.1.3 : Tue Oct 19 2004 - 23:37:52 EDT