2011-06-10 80 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

相關問題