加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

一个MSXML2.XMLHTTP的POST示例

(2013-02-26 11:23:32)
分类: js整理箱

<%
SearchWay="N"
CompanyName="餐饮集团"
StrPost="CompanyName="&CompanyName&"&SearchWay="&SearchWay&""
StrPost=toUTF8(StrPost)
Set Http = Server.CreateObject("MSXML2.XMLHttp")
Http.Open "Post","http://127.0.0.1/SearchList.asp",False
'//如果你硬要用request.form("CompanyName")来接收值,或者在php里面要用到$_POST接收,加入这一句
Http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Http.Send StrPost
'//如果你返回的是文本信息,用下面接收
ReSult = Http.ResponseText
'//如果你返回的是HTML文件,用下面接收
'ReSult = bytes2BSTR(Http.ResponseBody)
Response.Write ReSult 
'//这个是返回HTML文件信息时用的函数,如果返回文本信息,可以不需要这个函数
Function bytes2BSTR(vIn)
    Dim strReturn
    Dim I, ThisCharCode, NextCharCode
    strReturn = ""
    For I = 1 To LenB(vIn)
        ThisCharCode = AscB(MidB(vIn, I, 1))
        If ThisCharCode < &H80 Then
            strReturn = strReturn & Chr(ThisCharCode)
        Else
            NextCharCode = AscB(MidB(vIn, I + 1, 1))
            strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
            I = I + 1
        End If
    Next
    bytes2BSTR = strReturn
End Function
'//这个是对POST内容进行编码的函数
Function toUTF8(szInput)
    Dim wch, uch, szRet
    Dim x
    Dim nAsc, nAsc2, nAsc3
    
    If szInput = "" Then
        toUTF8 = szInput
        Exit Function
    End If
    For x = 1 To Len(szInput)
        wch = Mid(szInput, x, 1)
        nAsc = AscW(wch)
        If nAsc < 0 Then nAsc = nAsc + 65536
    
        If (nAsc And &HFF80) = 0 Then
            szRet = szRet & wch
        Else
            If (nAsc And &HF000) = 0 Then
                uch = "%" & Hex(((nAsc / 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80)
                szRet = szRet & uch
            Else
                uch = "%" & Hex((nAsc / 2 ^ 12) Or &HE0) & "%" & _
                            Hex((nAsc / 2 ^ 6) And &H3F Or &H80) & "%" & _
                            Hex(nAsc And &H3F Or &H80)
                szRet = szRet & uch
            End If
        End If
    Next
        
    toUTF8 = szRet
End Function
%>
SearchList.asp文件内容

<%
if request.form("SearchWay")="N" then
response.write request.form("companyname")
else
 response.write "NO VALUE"
end if
%>

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有