2011-06-10 81 views

回答

6
Sub XMLPost() 
Dim xmlhttp, sData As String 

    With ActiveSheet 
     sData = "x=" & URLencode(.Range("A2").Value) & _ 
       "&y=" & URLencode(.Range("B2").Value) 
    End With 

    Set xmlhttp = CreateObject("microsoft.xmlhttp") 

    With xmlhttp 
     .Open "POST", " http://testingHttpPost/", False 
     .setrequestheader "Content-Type", "application/x-www-form-urlencoded" 
     .send sData 
     Debug.Print .responsetext 
    End With 
End Sub 

对于URLEncode的功能在这里看到:How can I URL encode a string in Excel VBA?

+0

谢谢! Tim 在上例中,如果我想将数据插入到SQL Server数据库中。使用上面的HTTP Post示例,我怎样才能分别在表“DataTable”中的“X”和“Y”列中插入“x”和“y”数据? – user793468 2011-06-14 18:39:48

+0

对不起 - 我不熟悉asp.net(mvc)。通常,值X和Y将显示在request.form名称 - 值集合中。一旦你有了这些,你可以使用ADO来做插入。这与我所能提供的一样多。我建议你发表一个更具体的问题,包括你使用的是什么语言 – 2011-06-14 20:45:30

相关问题