使用 vba 和 xmlhttp 自动提交网站上的帖子表单
我在 excel 2010 中通过 vba 使用 xmlhttp
。我需要以编程方式将项目添加到网站上的购物车中。到目前为止,我有下面的代码,它使用 POST
方法
我认为我的代码有一些问题,但不确定如何修复 - 它没有显示表单所在的位置已提交。这是该网址:
http://www. craft-e-corner.com/p-2688-new-testament-cricut-cartridge.aspx
我作为处理表单的url输入的url是“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
I'm using xmlhttp
via vba in excel 2010. I need to programmatically add an item to a shopping cart on a website. I have the code below so far, it uses the POST
method
A couple of things I think are wrong with my code but not sure how to fix - It doesn't show where the form is that is being submitted. Here is that url:
http://www.craft-e-corner.com/p-2688-new-testament-cricut-cartridge.aspx
The url I entered as the url that processes the form is the url in the "action=" part of "form".
How can I verify that the form posted?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代码没有任何问题。 :) 我测试了一下,效果很好。错误可能在其他地方。
我只是稍微调整了代码以使用 IE 来测试输出,现在它工作得很好:) 我现在已经在 Excel 2007 中测试了它。很快将在 2010 年进行测试。顺便说一句,您使用的是哪个版本的 IE?
这是我测试过的代码,它工作得很好。
问候席
德
There is nothing wrong with the code. :) I tested it and it works fine. The error might be somewhere else.
I just tweaked the code little bit to use IE to test the output and it works just fine now :) I have tested it in Excel 2007 at the moment. Will test it in 2010 shortly. BTW which version of IE are you using?
Here is the code that I tested and it works just fine.
Regards
Sid
其他答案的变体适用于我,不需要 IE。
只需替换{花括号}中的三个值即可。
...以及后期绑定版本:
A variation of the other answer works for me without the need for IE.
Just replace the three values in {curly braces}.
...and a late-bound version: