文章摘要
文章介绍了两个自定义函数,用于处理数据传输和HTTP请求。第一个函数BytesToBstr,用于将二进制数据转换为字符串,涉及创建윈道普斯特流对象并设置属性如字符编码。第二个函数PostHTTPPage,用于执行POST请求并处理服务器响应,通过MSXML2创建HTTP客户端,设置请求头,发送数据并读取响应。文章重点在于展示这两个函数的代码实现及其功能用途。
function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject(“adodb.stream”)
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End function
‘==================================================function PostHTTPPage(url,data)
dim Http
set Http=server.createobject(“MSXML2.SERVERXMLHTTP.3.0”)
Http.open “POST”,url,false
Http.setRequestHeader “CONTENT-TYPE”, “text/plain”
Http.send(data)
if Http.readystate<>4 then
exit function
End if
PostHTTPPage=bytesToBSTR(Http.responseBody,”utf-8″)
set http=nothing
if err.number<>0 then err.Clear
End function
function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject(“adodb.stream”)
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End function
‘==================================================function PostHTTPPage(url,data)
dim Http
set Http=server.createobject(“MSXML2.SERVERXMLHTTP.3.0”)
Http.open “POST”,url,false
Http.setRequestHeader “CONTENT-TYPE”, “text/plain”
Http.send(data)
if Http.readystate<>4 then
exit function
End if
PostHTTPPage=bytesToBSTR(Http.responseBody,”utf-8″)
set http=nothing
if err.number<>0 then err.Clear
End function
© 版权声明
文章版权归作者所有,未经允许请勿转载。