Lotus Script NotesHTTPRequest Class returns double sized buffer for a GET request.
Daniel Nashed – 2 October 2024 08:42:00
I ran into this writing a new application published soon. It first looked like I got hit by the trailing CRLF.
But it turned out the buffer returned had the double len of what it should be.
This looks like a bug and there is already a SPR. HCL is investigating.
In my tests it is always double the size including the CRLF.
You could start searching for the end of the data. But how do you know where it ends?
My current work-around is to use the Content-Length header and truncate the string.
Here is a simple example of my work-around.
I would be interested if someone ran into similar issues. I tried all settings to prefer strings and UTF-8.
But this did not make a difference.
The returned JSON is not affected and returned differently.
I would like to hear from you if you ran into this too.
Or if you have different experiences and work-arounds.
-- Daniel
Function HttpGetRequest (URL As String) As String
Dim Session As New NotesSession
Dim headers As Variant
Dim req As NotesHTTPRequest
Dim ret As Variant
Dim HeaderName As String
Dim HeaderValue As String
Dim ResponseCode As Long
Dim ResponseText As String
Dim ContentLen As Long
Dim ResponseStr As String
HttpGetRequest = ""
ContentLen = 0
Set req = session.CreateHttpRequest()
req.maxredirects= 5
req.Preferstrings = True
Call req.SetHeaderField("Content-Type", "text/plain")
ret = req.Get (URL)
ResponseStr = req.ResponseCode
ResponseCode = Clng (Strtoken (ResponseStr, " ",2))
ResponseText = Strtoken (ResponseStr, " ",3)
headers = req.GetResponseHeaders()
Forall h In headers
HeaderName = Strleft (h, ":")
If ( HeaderName = "Content-Length") Then
HeaderValue = Strright (h, HeaderName + ": ")
ContentLen = Clng (HeaderValue)
End If
End Forall
If (200 = ResponseCode) Then
HttpGetRequest = Replace (Left (ret, ContentLen), Chr(13)+Chr(10), "")
End If
End Function
- Comments [0]