The BinaryRead method allows
the ASP pages read non-processed request content. In ALP the
processed/translated content which is available through the Form
collection is not available through the BinaryRead method. Therefore
the method usage makes sense only when the submitted data is not
encoded as standard post form. This is is most often an upload form:
<FORM METHOD="POST" ... enctype="multipart/form-data">
If the form is coded this way the browser posts the form fields
encoded in format different from the regular format. To keep ALP
compatible with the classic ASP ALP does not decode these form posts
automatically. Thus they must be decoded by the page using the
BinaryRead method. This is in fact relatively easy and there are many
samples showing how to do this, including a composite object that you
can use in your applications.
Syntax:
data = Request.BinaryRead(numBytes)
Parameters:
numBytes - can be 0 to Request.TotalBytes.
returned value - is an array of bytes (VT_UI1 | VT_ARRAY)
which is the standard format for binary data.
Examples:
str = ""
Function FormatHex(n,l)
Dim s
s = Hex(n)
While Len(s) < l
s = "0" & s
Wend
FormatHex = s
End Function
Response.Write FormatHex(0,8) & " "
RequestBin=Request.BinaryRead(Request.TotalBytes)
For i = 1 To Request.TotalBytes
j = (i - 1) Mod 16
c = MidB(RequestBin,i,1)
ln = FormatHex(AscB(c),2) & " "
Response.Write ln
if AscB(c) < 32 Or AscB(c) > 255 Then str = str & "." Else str = str & Chr(AscB(c))
If j >= 15 Then
Response.Write " " & Server.HTMLEncode(str)
Response.Write vbCrLf
str = ""
If i Mod 256 = 0 Then Response.Write vbCrLf
Response.Write FormatHex(i,8) & " "
End If
Next
The sample above dumps the binary data sent through the request. You
can use it to see how the browsers encode the data of the forms that use
enctype="multipart/form-data"
Remarks:
Although the ASP compatible pages in ALP can handle any data format
through the BinaryRead method, the browsers will send only multipart/form-data
encoded data. Another encoding may be used only if you use ALP
through a non-browser application. For example you can post custom
encoded data using the NetProbe
object.
Using the composite object from the samples to handle
multipart/form-data encoded forms is may be the best approach for ALP
applications and for applications that aim to run on both ALP and IIS.
Be aware that many of the 3-d party COM objects for upload handling may
have issues on some Windows versions and coding your application with
them may cause troubles.
Applies to: Request object
See also: The upload related samples. If you want
ready to use object for handling multipart/form-data uploads see the
upload component sample from the composite objects section.
|