views:

253

answers:

2

I'm trying to implement a REST interface under IIS5.1/ASP-classic (XP-Pro development box). So far, I cannot find the incantation required to retrieve request content variables under the PUT HTTP method.

With a request like:

PUT http://localhost/rest/default.asp?/record/1336

Department=Sales&Name=Jonathan%20Doe%203548

how do I read Department and Name values into my ASP code?

Request.Form appears to only support POST requests. Request.ServerVariables only gets me to header information. Request.QueryString doesn't get me to the content either...


Based on the replies from AnthonyWJones and ars I went down the BinaryRead path and came up with the first attempt below:

var byteCount = Request.TotalBytes;
var binContent = Request.BinaryRead(byteCount);
var myBinary = '';

var rst = Server.CreateObject('ADODB.Recordset');
rst.Fields.Append('myBinary', 201, byteCount);
rst.Open();
rst.AddNew();
rst('myBinary').AppendChunk(binContent);
rst.update();
var binaryString = rst('myBinary');
var contentString = binaryString.Value;

var parameters = {};
var pairs = HtmlDecode(contentString).split(/&/);
for(var pair in pairs) {
    var param = pairs[pair].split(/=/);
    parameters[param[0]] = decodeURI(param[1]);
}

This blog post by David Wang, and an HtmlDecode() function taken from Andy Oakley at blogs.msdn.com, also helped a lot.

Doing this splitting and escaping by hand, I'm sure there are a 1001 bugs in here but at least I'm moving again. Thanks.

A: 

Unfortunately ASP predates the REST concept by quite some years.

If you are going RESTFull then I would consider not using url encoded form data. Use XML instead. You will be able to accept an XML entity body with:-

 Dim xml : Set xml = CreateObject("MSXML2.DOMDocument.3.0")
 xml.async = false
 xml.Load Request

Otherwise you will need to use BinaryRead on the Request object and then laboriously convert the byte array to text then parse the url encoding yourself along with decoding the escape sequences.

AnthonyWJones
Unfortunately, the body content format is pretty much fixed. Looks like I'll have to chase down binary reads.
aczarnowski
A: 

Try using the BinaryRead method in the Request object:

http://www.w3schools.com/ASP/met_binaryread.asp

Other options are to write an ASP server component or ISAPI filter:

http://www.codeproject.com/KB/asp/cookie.aspx

ars