How to access https RequestHeader when using a TextStream

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Herb40
Posts: 134
Joined: Thu May 08, 2014 3:35 am

How to access https RequestHeader when using a TextStream

Post by Herb40 »

I want to receive a CSV response from a web site using a TextStream, as in:

Code: Select all

  URL = "https://the rest of the URL”
  oSFA = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
  oTextStream = CreateUnoService("com.sun.star.io.TextInputStream")	
  oStream = oSFA.openFileRead(URL)
  oTextStream.setInputStream(oStream)
This approach has worked just fine for me. However, I now need to add a RequestHeader to the https request. Is it possible to access the https RequestHeaders in one of these objects so a new RequestHeader can be added?

I know that I can use

Code: Select all

  URL = "https://the rest of the URL”
  oHttp = CreateObject("Winhttp.WinHttpRequest.5.1")  
  With oHttp
    .Open "GET", URL, False
    .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) …
    .setRequestHeader "another header”
    .setRequestHeader “still more headers”
    .setRequestHeader "MyName”,”MyValue”
    .send
  End With
where the last .setRequestHeader with MyName,MyValue is the one I need to add. Can I somehow add this one to the TextStream approach?
OpenOffice 4.1.3 on Windows 10
Post Reply