HTTP request headers

Hi there where ever you are :slightly_smiling_face:

This works in the case that the server does not
require the HEADER parts of the requests to be set:

Sub GetStocks

    Dim URL As String
    Dim response As String
    Dim pos As Long
    Dim oServiceManager As Object
    Dim oSimpleFileAccess As Object
    Dim oInputStream As Object
    Dim oTextInputStream As Object

    URL = "https://example.com/stocks/" '(does not match the domain name used)
    oServiceManager = GetProcessServiceManager()
    oSimpleFileAccess = oServiceManager.createInstance("com.sun.star.ucb.SimpleFileAccess")
    oInText = createUNOService("com.sun.star.io.TextInputStream")
    oInputStream = oSimpleFileAccess.openFileRead(URL)
    oInText.setInputStream(oInputStream)
   	
    Do While Not oInText.isEOF()
        line = oInText.readLine()
        response = response & line & Chr(10)
    Loop
    ...
    ...	

End Sub

I can’t get this working:

Sub GetStocksWithHeaders()

    Dim URL As String
    Dim response As String
    Dim oServiceManager As Object
    Dim oWebDAV As Object
    Dim oInputStream As Object
    Dim oTextInputStream As Object

    URL = "https://example.com/stocks/"
    oServiceManager = GetProcessServiceManager()
    oWebDAV = oServiceManager.createInstance("com.sun.star.ucb.WebDAVDocumentContent")

    REM The code fails here:
    oWebDAV.setPropertyValue("URL", URL)
    REM Returns:
    REM BASIC execution error.
    REM '91'
    REM Object variable not defined.

    'This makes no difference:
    'oWebDAV.setPropertyValue("GET", URL, False)

    oWebDAV.setPropertyValue("ContentType", "text/json")
    oWebDAV.setPropertyValue("UserAgent", "LibreOffice")

    oInputStream = oWebDAV.openInputStream()
    oTextInputStream = createUNOService("com.sun.star.io.TextInputStream")
    oTextInputStream.setInputStream(oInputStream)

    response = ""
    Do While Not oTextInputStream.isEOF()
        response = response & oTextInputStream.readLine()
    Loop

    oTextInputStream.closeInput()
    oInputStream.closeInput()

    ...
    ...

End Sub

You do not create the content like that. You request it from the content broker, like this:

  b = CreateUnoService("com.sun.star.ucb.UniversalContentBroker")
  id = b.createContentIdentifier("https://www.libreoffice.org")
  c = b.queryContent(id)

See the documentation.

Are you serious?

Sorry, I have no idea what you expect to that. If you have some specific question, please ask clearly. Note that I posted a comment, not an answer, so it wasn’t intended as w complete answer, only as some pointer in the direction that you may need to investigate.

Well, I’m working on Windows so best to keep things simple and use the CreateObject(“Msxml2.ServerXMLHTTP.6.0”) method :upside_down_face: