从Excel向WebService发送POST请求

时间:2015-06-20 06:58:35

标签: excel web-services

我们有一个场景要求我们将POST请求从Excel发送到Web服务。

对API的示例请求: http://localhost/api/createticket?name=mark&rowNumber=65

参数(name& rowNumber)应取自Excel单元格。

如何实现这一目标?

2 个答案:

答案 0 :(得分:0)

最后,我采取了微软文章中详述的步骤。

答案 1 :(得分:0)

典型例子涉及VBA脚本(Excel中Alt+F11编辑):

Dim oX as Object
Set oX = CreateObject("Msxml2.XMLHTTP") ' there are many versions of this object, look around
Dim URL = "http://your.server.url/webservice/"
oHttp.Open "POST", URL, False
oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Dim data As String ' this looks like querystring but is actually a POST body
data = data & "&SITE=LM"
data = data & "&NSP=999"
oHttp.send (data)
Dim response = oHttp.responseText
MsgBox response

不幸的是,ActiveX 函数 CreateObject 在我的工作机器上失败了,我预计它在许多环境中会越来越多地被阻止。

一个快速且简单的替代方法是 WEBSERVICE 函数,但它似乎只允许没有正文和身份验证的 GET 请求:

=WEBSERVICE("http://mywebservice.com/serviceEndpoint?searchString=Excel")

更多:(Expo) Uncaught Error: java.net.SocketTimeoutException: failed to connect to /10.x.x.xx (port xxxxx) from /192.xxx.x.xxx (port xxxxx) after 1000ms