UserPreferences

RestAspExample


Rest ASP Example

This page describes how to get an ASP application to work with the PUT and DELETE verbs under IIS on Windows XP Professional. Other versions of IIS / Windows may vary in configuration, but the process should be almost identically.

IIS configuration

The requesting script

Now, the application is configured, and it's just to write a test script. To test PUT and DELETE functionality, we need a way to request an ASP-script directly from ASP-code, and not via HTML forms etc. The way to do this, is to use the [WWW]ServerXMLHttp object. This is the code for the requesting script:

<%@ Language = "VBScript" LCID = 1044 %>
<%

  Option Explicit
  Response.CharSet     = "ISO-8859-1"
  Response.ContentType = "text/plain"
  Response.Buffer      = True
  Response.Expires     = 0
  
  Dim xmlhttp
  
  Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
  
  ' Open up a connection to the receiving script with a method of "PUT"
  Call xmlhttp.open("PUT", "http://localhost/test/verb_test2.asp", False)
  
  ' Send some data
  xmlhttp.send("<feed><title>Hello!</title></feed>")
  
  ' This will contain the response from verbtest2 in plain text. There are other response-properties
  ' as well, like "responseBody", "responseStream" and "responseXML".
  Response.Write(xmlhttp.responseText)

%>

The receiving script

And this is the code for the receiving script:

<%@ Language = "VBScript" LCID = 1044 %>
<%

  Option Explicit
  Response.CharSet     = "ISO-8859-1"
  Response.ContentType = "text/plain"
  Response.Buffer      = True
  Response.Expires     = 0
  
  ' This function converts a byte array to a conventional string
  Function BinaryToString(Binary)
    Dim i, s

    For i = 1 To LenB(Binary)
      s = s & Chr(AscB(MidB(Binary, i, 1)))
    Next

    BinaryToString = s
  End Function

  ' This will output whatever received from the requesting/sending script above
  Response.Write(BinaryToString(Request.BinaryRead(Request.TotalBytes)))

%>

Discuss


Original Author: AsbjornUlsberg

CategoryApi, CategoryRest