问题描述
我在 excel 2010 中通过 vba 使用 xmlhttp
.我需要以编程方式将商品添加到网站上的购物车中.到目前为止,我有下面的代码,它使用 POST
方法
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
我作为处理表单的 url 输入的 url 是表单"的action="部分中的 url.
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
推荐答案
代码没有问题.:) 我测试了它,它工作正常.错误可能在其他地方.
There is nothing wrong with the code. :) I tested it and it works fine. The error might be somewhere else.
我只是稍微调整了代码以使用 IE 来测试输出,现在它工作得很好:) 目前我已经在 Excel 2007 中对其进行了测试.不久将在 2010 年对其进行测试.顺便说一句,您使用的是哪个版本的 IE?
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.
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", "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"
response = xmlhttp.responseText
objIE.document.Write response
Set xmlhttp = Nothing
End Sub
问候
席德
这篇关于使用 vba 和 xmlhttp 自动提交网站上的帖子表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!