OpenOffice:如何从http地址加载数据?

时间:2016-05-13 18:14:45

标签: openoffice-basic

使用Openoffice宏,我想从本地网络服务器加载数据。我试过这段代码:

Dim stringWeb As String, webAddr As String
Dim doc As Object
Dim opts(0) As New com.sun.star.beans.PropertyValue

webAddr = "http://127.0.0.1:8080"

opts(0).Name = "Hidden"
opts(0).Value = True

doc = StarDesktop.loadComponentFromURL(webAddr, "_blank", 0, opts)
stringWeb = doc.Text.String
doc.close(True)

MsgBox(stringWeb, 0, "Result")

此代码有效,但是当网络服务器不在端口80上侦听时怎么办? (例如,在端口8080上) 我试过webAddr =“http://127.0.0.1:8080”,但它不起作用:(

有人可以帮助我吗?感谢。

编辑:或许有这种代码?

Dim vParser, vDisp
Dim oUrl As New com.sun.star.util.URL
oUrl.Complete = "http://127.0.0.1:8080"
vParser = createUnoService("com.sun.star.util.URLTransformer")
vParser.parseStrict(oUrl)

vDisp = StarDesktop.queryDispatch(oUrl, "", 0)
If (Not IsNull(vDisp)) Then vDisp.dispatch(oUrl, noargs())

但我不知道如何使用它:/

2 个答案:

答案 0 :(得分:1)

这有效:

webAddr = "http://178.33.250.62:8080/"  'portquiz.net

在我的机器上我根本没有运行Web服务器,因此以下结果导致IllegalArgumentException(“不支持的URL”):

webAddr = "http://127.0.0.1"

然后,似乎问题与OpenOffice或Basic无关。相反,问题在于您的Web服务器的配置方式。

答案 1 :(得分:0)

实际上,Apache向Web服务器发送了一个PROPFIND命令(在GET之前)。而我的网络服务器并不知道这个命令。

标题发送:

PROPFIND / HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Apache OpenOffice/4.1.2
Accept-Encoding: gzip
Depth: 0
Content-Type: application/xml
Content-Length: 259

<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"><prop><resourcetype xmlnx="DAV:"/><IsReadOnly xmlnx="http://ucb.openoffice.org/dav/props/"/><getcontenttype xmlnx="DAV:"/><supportedlock xmlnx="DAV:"/><lockdiscovery xmlnx="DAV:"/></prop></propfind>