加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

表单 – 使用vba和xmlhttp自动提交网站上的帖子表单

发布时间:2020-12-14 21:21:01 所属栏目:资源 来源:网络整理
导读:我在excel 2010中通过vba使用xmlhttp.我需要以编程方式将项目添加到网站上的购物车中.到目前为止我有下面的代码,它使用POST方法 我认为我的代码有些错误,但不确定如何修复 – 它没有显示提交表单的位置.这是网址: http://www.craft-e-corner.com/p-2688-new
我在excel 2010中通过vba使用xmlhttp.我需要以编程方式将项目添加到网站上的购物车中.到目前为止我有下面的代码,它使用POST方法

我认为我的代码有些错误,但不确定如何修复 – 它没有显示提交表单的位置.这是网址:

http://www.craft-e-corner.com/p-2688-new-testament-cricut-cartridge.aspx

我输入的url作为处理表单的url是“form”中“action =”部分的url.

如何验证表单已发布?

Sub post_frm()
Dim xmlhttp As Object
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
' Indicate that page that will receive the request and the
' type of request being submitted
xmlhttp.Open "POST","http://www.craft-e-corner.com/addtocart.aspx?returnurl=showproduct.aspx%3fProductID%3d2688%26SEName%3dnew-testament-cricut-cartridge",False
' Indicate that the body of the request contains form data
xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
' Send the data as name/value pairs
xmlhttp.send "Quantity=1&VariantID=2705&ProductID=2688"
Set xmlhttp = Nothing
End Sub

解决方法

代码没有任何问题. :)我测试了它,它工作正常.错误可能在其他地方.

我只是稍微调整了代码以使用IE来测试输出,它现在工作得很好:)我已经在Excel 2007中测试了它.不久将在2010年进行测试. BTW您使用的是哪个版本的IE?

这是我测试的代码,它工作得很好.

Option Explicit

Sub post_frm()

    Dim objIE As Object,xmlhttp As Object
    Dim response As String

    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.navigate "about:blank"
    objIE.Visible = True

    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")

    '~~> Indicates that page that will receive the request and the type of request being submitted
    xmlhttp.Open "POST",False
    '~~> Indicate that the body of the request contains form data
    xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
    '~~> Send the data as name/value pairs
    xmlhttp.Send "Quantity=1&VariantID=2705&ProductID=2688"

    response = xmlhttp.responseText
    objIE.document.Write response

    Set xmlhttp = Nothing

End Sub

问候

希德

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读