如何使用 MSXML2.ServerXMLHTTP 从另一个站点获取数据? [英] How do I use MSXML2.ServerXMLHTTP to grab data from another site?

查看:24
本文介绍了如何使用 MSXML2.ServerXMLHTTP 从另一个站点获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有以下链接:http://mvp.sos.state.ga.us/

与其创建一个数据库来复制 MVP 页面的信息,我们更愿意使用我们自己的表单,然后在幕后,使用名为 MSXML2.ServerXMLHTTP 的组件将信息发送到上面的站点以获取结果.

Rather than create a db to replicate information that MVP page, we would like to use our own form, and then behind the scenes, send information to the site above to get results back using component called MSXML2.ServerXMLHTTP.

很遗憾,我对这个组件或如何使用它一无所知.

Unfortunately, I know nothing about this component or how to use it.

能否请人指点一下如何使用我们自己的...将信息发送到上面的站点并将结果返回到我们的表单中?

Would someone be kind enough to please give me pointers on how use our own ... to send information to the site above and get results back to our form?

我们基本上是想让用户输入名字的首字母、姓氏、县、出生日期.

We are basically trying to get users to enter first initial, lastname, county, date of birth.

谢谢

推荐答案

您可以将此组件用于 http 请求,如POST"、GET"、DELETE"等.

You can use this component for http-requests like "POST", "GET", "DELETE" etc.

创建对象:

<%
    Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
%>

使用GET"方法发送数据:

<%
    objXML.Open "GET", "http://mvp.sos.state.ga.us/?some=querystring", false 
    objXML.Send ""
    Response.Write objXML.responseText
%>

注意Open方法有3个参数:HTTP方法、URL、异步调用.

Note that Open method has 3 parameters: HTTP method, URL, asynchronous call.

请注意,GET"上的 Send 方法会忽略其参数.(在这种情况下,我们通过 URL 传递参数.)

Note that Send method on a "GET" ignores its parameter. (In this case we are passing parameters via the URL.)

使用POST"方法发送数据:

<%
    objXML.Open "POST", "http://mvp.sos.state.ga.us/", false 
    objXML.Send "username=htbasaran&password=somepassword"
    Response.Write objXML.responseText
%>

注意POST",Send 方法以键值对格式传递参数,例如:key1=value1&key2=value2&so=on... 或任何其他数据,例如 XML、JSON等)

Note for "POST" that Send method passes parameters in key-value pairs format like: key1=value1&key2=value2&so=on... or any other data like XML, JSON, etc.)

这些是这个组件的基础.如果您需要更多信息,可以查看 microsoft 的文档页面 出来了.

These are the basics of this component. If you need more information, you can check microsoft's docs page out.

获取表单值并使用 xmlhttp post 方法发送它们的示例代码.

<%
    ' getting form values
    my_uname = Request.Form("username")
    my_pword = Request.Form("password")

    ' creating object
    Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")

    ' sending variables to an external site
    objXML.Open "POST", "http://www.sitename.com/login.asp", false
    objXML.Send "username=" & my_uname & "&password=" & my_pword

    ' Assuming that successful login will return response "Ok"
    ' writing the result to the client.
    if objXML.responseText="Ok" then
        Response.Write "Login Successful!"
    else
        Response.Write "Login Failed!"
    end if
%>

这篇关于如何使用 MSXML2.ServerXMLHTTP 从另一个站点获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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