How can I send an HTTP POST request to a server from Excel using VBA?

前端 未结 6 1985
执笔经年
执笔经年 2020-11-22 08:01

What VBA code is required to perform an HTTP POST from an Excel spreadsheet?

6条回答
  •  孤独总比滥情好
    2020-11-22 08:34

    In addition to the anwser of Bill the Lizard:

    Most of the backends parse the raw post data. In PHP for example, you will have an array $_POST in which individual variables within the post data will be stored. In this case you have to use an additional header "Content-type: application/x-www-form-urlencoded":

    Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    URL = "http://www.somedomain.com"
    objHTTP.Open "POST", URL, False
    objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
    objHTTP.send ("var1=value1&var2=value2&var3=value3")
    

    Otherwise you have to read the raw post data on the variable "$HTTP_RAW_POST_DATA".

提交回复
热议问题