另一个网站使用POST方法给我发送数据。
我想将这些数据插入到数据库中。
在网上做了一些研究后,我得出结论,ADODB.Stream应该为我做这项工作。
我用Request.TotalBytes获取二进制数据没有问题。使用下面的代码,我没有收到错误,但它也没有保存数据。所以我一定是对ADODB流做错了什么。
tot_bytes = Request.TotalBytes
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Mode = 3
BinaryStream.Type = 1
BinaryStream.Open
gBinaryData = BinaryStream.Write(tot_bytes)
BinaryStream.Close
Set BinaryStream = Nothing
SQL = "INSERT INTO STATUSES (StatusMessage, StatusDateEntered) VALUES ('"& gBinaryData &"', '"& FormatDateMySQL(NOW) &"')"
Set objAddC = objConn.execute(SQL)。
Following a successful subscription, Facebook will proceed to call your endpoint every time that there are changes (to the chosen fields or connections). For each update, it will make an HTTP POST request.
The request will have content type of application/json and the body will comprise a JSON-encoded string containing one or more changes.
Note for PHP developers: In PHP, to get the encoded data you would use the following code:
$data = file_get_contents("php://input");
$json = json_decode($data);发布于 2013-03-18 07:08:03
首先,方法不返回任何东西,实际上它只是一个子例程。而Request.TotalBytes只是请求的字节长度。当您需要以字节数组的形式读取请求数据时,您应该使用Request.BinaryRead(字节长度)。因此,在Stream对象中,需要在写入字节之后使用方法读取所有字节,并将位置设置为开始位置。
我假设您需要文本形式的数据,很可能是json字符串。因此,您应该将数据从字节转换为字符串。
请注意,您需要处理有关总字节数的异常。如果请求不包含任何内容,则Request.TotalBytes等于零,并且由于Request.BinaryRead期望一个大于零且小于或等于总字节数的数字,因此发生错误。
Dim tot_bytes, postData
tot_bytes = Request.TotalBytes
If tot_bytes > 0 Then
With Server.CreateObject("Adodb.Stream")
.Charset = "utf-8" 'specify the request encoding
.Type = 1 'adTypeBinary, a binary stream
.Open
.Write Request.BinaryRead(tot_bytes) 'Write bytes
.Position = 0 ' set position to the start
.Type = 2 ' adTypeText, stream type is text now
postData = .ReadText 'read all text
.Close
End With
With Server.CreateObject("Adodb.Recordset")
.Open "STATUSES", objConn , , 3
.AddNew
.Fields("StatusMessage").Value = postData
.Fields("StatusDateEntered").Value = Now()
.Update
.Close
End With
Response.Write "data stored successfully"
Else
Response.Write "no post data"
End If发布于 2013-03-18 02:15:22
除了像这样直接将数据插入到数据库中是一个非常糟糕的想法(可能是sql注入)之外,如何发布表单数据?CLassic ASP也不能直接处理二进制数据。所以这根本不会起作用。
所以无论你发布什么,首先你必须确保你发布的是表单enctype="multiform/data"。要将数据放入对象中,请尝试执行以下操作:
byteArray = Request.BinaryRead(Request.TotalBytes)BUt要处理它,存储到数据库或保存到文件,你需要一个组件,例如http://www.motobit.com/help/scptutl/upload.asp或尝试检查这篇文章(特别是当你上传多个文件时):http://www.codeguru.com/csharp/.net/net_asp/article.php/c19297/Pure-ASP-File-Upload.htm。
编辑: Antonin Fuller也在没有使用他的DLL的情况下制作了一个示例ASP代码。也试试这个:
Private Function RSBinaryToString(xBinary)
'Antonin Foller, http://www.motobit.com
'RSBinaryToString converts binary data (VT_UI1 | VT_ARRAY Or MultiByte string)
'to a string (BSTR) using ADO recordset
Dim Binary
'MultiByte data must be converted To VT_UI1 | VT_ARRAY first.
If vartype(xBinary)=8 Then Binary = MultiByteToBinary(xBinary) Else Binary = xBinary
Dim RS, LBinary
Const adLongVarChar = 201
Set RS = CreateObject("ADODB.Recordset")
LBinary = LenB(Binary)
If LBinary>0 Then
RS.Fields.Append "mBinary", adLongVarChar, LBinary
RS.Open
RS.AddNew
RS("mBinary").AppendChunk Binary
RS.Update
RSBinaryToString = RS("mBinary")
Else
RSBinaryToString = ""
End If
End Function点击此处查看更多信息:http://www.motobit.com/tips/detpg_binarytostring/
最后,您应该获取流,对其进行转换并使用它。
https://stackoverflow.com/questions/15464221
复制相似问题