Forms 使用vba和xmlhttp自动提交网站上的帖子表单
我正在通过excel 2010中的vba使用Forms 使用vba和xmlhttp自动提交网站上的帖子表单,forms,vba,excel-2010,xmlhttprequest,Forms,Vba,Excel 2010,Xmlhttprequest,我正在通过excel 2010中的vba使用xmlhttp。我需要以编程方式将一个项目添加到网站上的购物车中。到目前为止,我有下面的代码,它使用POST方法 我认为我的代码有一些地方是错误的,但不确定如何修复——它没有显示提交表单的位置。以下是该url: 我作为处理表单的url输入的url是“action=”表单的一部分”中的url 我如何验证该表单是否已发布 Sub post_frm() Dim xmlhttp As Object Set xmlhttp = CreateObject("MS
xmlhttp
。我需要以编程方式将一个项目添加到网站上的购物车中。到目前为止,我有下面的代码,它使用POST
方法
我认为我的代码有一些地方是错误的,但不确定如何修复——它没有显示提交表单的位置。以下是该url:
我作为处理表单的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
代码没有问题。:)我测试过了,效果很好。错误可能在其他地方 我只是稍微调整了一下代码,用IE来测试输出,现在效果很好:)我已经在Excel2007中测试过了。不久将在2010年进行测试。顺便问一下,你使用的是哪个版本的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", "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
问候
Sid是我不需要IE的其他作品的变体
Sub Post_HTTP_Form()
'Requires reference to "Microsoft XML, v6.0" or better. (Tools>References)
Dim msXML As New XMLHTTP60, resp As String
With msXML
.Open "POST", "{http://YOUR_URL_HERE.com}", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send "{PARAMETER}={VALUE}"
resp = StrConv(.responseBody, vbUnicode)
End With
Debug.Print resp 'outputs to Immediate Window (CTRL+G to view)
Set msXML = Nothing
End Sub
只需替换{大括号}中的三个值
…和一个版本:
Sub Post_HTTP_Form()
Dim msXML As Object, resp As String
Set msXML = CreateObject("MSXML2.ServerXMLHTTP")
With msXML
.Open "POST", "{http://YOUR_URL_HERE.com}", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send "{PARAMETER}={VALUE}"
resp = StrConv(.responseBody, vbUnicode)
End With
Debug.Print resp 'outputs to Immediate Window (CTRL+G to view)
Set msXML = Nothing
End Sub