To bypass the cross-domain limitations of AJAX requests, we have a proxy agent that takes in a URL and should return the contents of the URL.
Until now, the agent has been in Java. It has normally worked fine, but every once in a while it’ll hang and just keep writing warnings to the server log (XXX minute(s) have elapsed since start of agent ‘YYY’). So I’m trying to write the agent in LotusScript instead (but if anyone has a solution to the Java agent problem, please post!)
The problem I’m having now is with character sets. We have some pages with weird codepages (one uses windows-1252 for example), so I need to support that. So I made the agent like this:
(a bunch of code to read the URL and desired encoding from the query string)
Dim req As Variant
Set req = CreateObject(“Msxml2.ServerXMLHTTP.3.0”)
Call req.SetTimeouts(10000, 10000, 10000, 30000) ’ 10s for DNS, connect, and send; 30s for receive
Call req.Open(“GET”, url, False)
Call req.Send()
(code to print Content-Type: XXX; charset=YYY depending on the query string settings)
print req.responseText
This works for UTF-8 and ISO-8859-1 (Western European ISO). However, for windows-1252, some kind of conversion is done on the string that ends up trashing special characters (they get converted to an escaped Unicode sequence that overwrites some of the data).
For example, Färdigställning gets converted to F■igst■ning. I can’t just reverse the conversion, because it has overwritten a bunch of the normal characters.
I can get around this by reading binary data instead:
Dim responseString As String
Dim responseBody As Variant
responseBody = req.ResponseBody
Dim i As Long
For i = Lbound(responseBody) To Ubound(responseBody)
responseString = responseString & Chr(responseBody(i))
Next
Print responseString
But this fails if there is more data than a LotusScript array supports (32K I think).
I’ve tried playing around with an ADODB.Stream object, but I can’t get the data loaded into it. Doing something like:
stream.Write(req.responseBody)
still fails if the array is too big, even though I don’t want to access it like an array. If LotusScript would just pass it along as a pointer, it’d probably work, but I don’t think it’s possible to force it to do this.
Anyone have any ideas? Can I do the lookup using API calls instead maybe?
- Bruce