获取访问二元响应逐字节在传统的ASP / JScript的 [英] Getting access to a binary response byte-by-byte in classic asp/JScript

查看:190
本文介绍了获取访问二元响应逐字节在传统的ASP / JScript的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问这个问题前几天,但它似乎已经相当快凉了。我想要做的是pretty简单,我不能相信有人没有意识到这一点。

I asked this question a few days ago but it seems to have gone cold fairly quickly. What I want to do is pretty simple and I can't believe someone hasn't figured it out.

解决方案需要的JScript传统的ASP。我读从远程服务器上的文件,我想处理我的服务器上(二进制)文件和吐结果返回给客户端的XML。

Solution needs to be JScript classic ASP. I am reading a file from a remote server and I want to process that (binary) file on my server and spit the results back to the client as XML.

这里是什么,我试图做一个简化版本。这code运行时,还是会如果URL中填写您的网站。此文件是readbin.asp。它读取一个称为TEST.bin,烧写文件,并把结果写入数据流。我用了一个流,因为这使得它更容易阅读文件并解析的内容。基本上我想:

Here's a simplified version of what I am trying to do. This code runs, or will if the URL is filled in for your site. This test file is readbin.asp. It reads a file called test.bin, and writes the result to a stream. I used a stream because that makes it easier to read the file and parse the contents. Basically I want to:

while not end of stream
    read byte from stream
    process byte

下面是readbin.asp:

here is readbin.asp:

<%@ LANGUAGE = JScript %>
<%
var url = "http:// (... your URL to the file test.bin goes here...) " ; 
var xmlhttp = Server.CreateObject ("MSXML2.ServerXMLHTTP") ;
xmlhttp.open ("GET", url, false) ; 
xmlhttp.send () ; 

var BinaryInputStream = Server.CreateObject ("ADODB.Stream") ;
BinaryInputStream.Type = 1 ; // binary
BinaryInputStream.Open ;
BinaryInputStream.Write (xmlhttp.responseBody) ;
BinaryInputStream.Position = 0 ;

Response.Write ("BinaryInputStream.size = " + BinaryInputStream.size + "<br>") ;
Response.Write ("BinaryInputStream = " + BinaryInputStream + "<br>") ;

var ByteValue = BinaryInputStream.read (1) ;
Response.Write ("ByteValue = " + ByteValue + "<br>") ;
Response.Write ("typeof (ByteValue) = " + typeof (ByteValue) + "<br>") ;
%>

我的问题是:我如何才能作为的byteValue一些0..255? typeof运算(的byteValue)是未知。

My problem is: how do I get ByteValue as a number 0..255? typeof (ByteValue) is "unknown".

奥德?字节()?? ASC? CHR 13

Ord?? Byte()?? Asc?? Chr??

推荐答案

也许不太上的话题,而是使用VBScript我写这样的:

Maybe not quite on the topic, but using VBScript I wrote this:

option explicit
dim fso, wshSHell, objShellApp, args, stdin,stdout

set fso         = CreateObject("Scripting.FileSystemObject")
Set wshShell    = CreateObject("WScript.Shell")
set objShellApp = CreateObject("Shell.Application")
Set args = Wscript.Arguments
set stdin = wscript.stdin
set stdout = wscript.stdout

dim filename, txtFile

filename = args(0)

Const adTypeBinary = 1

'Create Stream object
Dim BinaryStream, data
Set BinaryStream = CreateObject("ADODB.Stream")

'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeBinary

'Open the stream
BinaryStream.Open

'Load the file data from disk To stream object
BinaryStream.LoadFromFile filename

'Open the stream And get binary data from the object
data = BinaryStream.Read
BinaryStream.close

dim i, item, strLine, hexLine
hexLine = ""
strLine = ""

stdout.writeline "Decimal |Hex     |Data                                             | ASCII 33-254"
for i = 0 to lenb(data)-1
  item = ascb(midb(data,i+1,1))
  if ((i MOD 16) = 0) and (i<>0) then
    stdout.writeLine right("00000000" & i,8) & "|" & right("00000000" & hex(i),8) & "|" &  hexLine & " | " & strLine
    hexLine = ""
    strLine = ""
  end if
  hexLine = hexLine & right("0" & hex(item),2) & " "
  if (item <= 32) or (item > 254) then 
    strLine=strLine + "."
  else
    strLine = strLine & chr(item)
  end if
next

密钥到该溶液是要知道变量'数据'包含一个字节数组。您可以通过使用功能LENB(字节数组的长度)和MIDB(提取一个或多个字节)处理的。

Key to this solution is to know that the variable 'data' contains an array of bytes. You can handle that by using the function lenb (length of byte array) and midb (to extract one or more bytes).

运行脚本如下:

cscript dumphex.vbs my_binary_file.bin > my_binary_file.hex.txt

这将输出到标准输出的所有二进制文件数据的十六进制code。 16进制codeS的每一行是由字节数的小数+进制计数器pfixed $ P $。最后一栏显示33和254之间可读的ASCII

This will output to standard out the hex code of all the binary file data. Each line of 16 hex codes is prefixed by a decimal + hex counter of the byte number. THe last column displays readable ascii between 33 and 254.

也大规避烦人的编辑器,跨$ P $其中pts的UTF-8 codeS,如果你只希望看到确切的codeS在你的ASCII文件。

Also great to circumvent that annoying editor that interprets your UTF-8 codes, if you want to see just the exact codes in your ascii files.

这篇关于获取访问二元响应逐字节在传统的ASP / JScript的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆