ASP 抓取 enctype="multipart/form-data" 编码过的数据

来源:百度文库 编辑:神马文学网 时间:2024/04/28 13:00:20
ASP 抓取 enctype="multipart/form-data" 编码过的数据2009-03-04 01:23
  1. Dim FormData, FormSize, Divider, bCrLf   
  2. FormSize = Request.TotalBytes   
  3. FormData = Request.BinaryRead(FormSize)   
  4. bCrLf = ChrB(13) & ChrB(10)   
  5. Divider = LeftB(FormData, InStrB(FormData, bCrLf) - 1)   
  6.   
  7. Function GetFormVal(FormName)   
  8.      GetFormVal = ""  
  9.      StartPos = LenB(Divider) + 2   
  10.      FormName = Chr(34) & FormName & Chr(34)   
  11.     Do While StartPos > 0   
  12.          strlen = InStrB(StartPos, FormData, bCrLf) - StartPos   
  13.          SearchStr = MidB(FormData, StartPos, strlen)   
  14.         If InStr(bin2str(SearchStr), FormName) > 0 Then  
  15.              ValStart = InStrB(StartPos, FormData, bCrLf & bCrLf) + 4   
  16.              ValLen = InStrB(StartPos, FormData, Divider) - 2 - ValStart   
  17.              ValContent = MidB(FormData, ValStart, ValLen)   
  18.             If GetFormVal <> "" Then  
  19.                  GetFormVal = GetFormVal & "," & bin2str(ValContent)   
  20.             Else  
  21.                  GetFormVal = bin2str(ValContent)   
  22.             End If  
  23.         End If  
  24.         If InStrB(StartPos, FormData, Divider) < 1 Then  
  25.             Exit Do  
  26.         End If  
  27.          StartPos = InStrB(StartPos, FormData, Divider) + LenB(Divider) + 2   
  28.     Loop  
  29. End Function  
  30.   
  31. Function bin2str(binstr)   
  32.     Dim varlen, clow, ccc, skipflag   
  33.      skipflag = 0   
  34.      ccc = ""  
  35.      varlen = LenB(binstr)   
  36.     For i = 1 To varlen   
  37.         If skipflag = 0 Then  
  38.              clow = MidB(binstr, i, 1)   
  39.             If AscB(clow) > 127 Then  
  40.                  ccc = ccc & Chr(AscW(MidB(binstr, i + 1, 1) & clow))   
  41.                  skipflag = 1   
  42.             Else  
  43.                  ccc = ccc & Chr(AscB(clow))   
  44.             End If  
  45.         Else  
  46.              skipflag = 0   
  47.         End If  
  48.     Next  
  49.      bin2str = ccc   
  50. End Function  
  51.   
  52. Function str2bin(str)   
  53.     For i = 1 To Len(str)   
  54.          str2bin = str2bin & ChrB(Asc(Mid(str, i, 1)))   
  55.     Next  
  56. End Function  
  57.   
  58. Response.Write GetFormVal("T1")