0

I have these ASP script for cache

fn = "caches/"&md5(url)&".html"

// Grab HTML file from site
set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
oXMLHTTP.Open "GET", url, false
oXMLHTTP.Send

// Save it
set fs = Server.CreateObject("Scripting.FileSystemObject")
set file = fs.CreateTextfile(fn,false,true)
file.Write oXMLHTTP.responseText
file.close

// Open it and print to screen
set file = fs.OpenTextFile(fn,1)
response.write file.ReadAll
file.Close
response.end

Saved files are "Unicode BOM" encoded, and this causes char problems. When I am convert encoding to "ANSI", everything becomes look normal as expected.

How to covert "oXMLHTTP.responseText" to "ANSI" programaticly?

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
Digerkam
  • 1,826
  • 4
  • 24
  • 39
  • I recommend using `Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")` - it's the most recent version of MSXML – John Jan 17 '16 at 15:15

1 Answers1

0

Best practice is saving binary instead of text always. You can access response binary by using oXMLHTTP.responseBody instead.
However, if you are sure that the response text is compatible with your locale, it is safe to save the response text in ANSI with no problem.
To do this, you need to pass False for third parameter of CreateTextFile method.

set file = fs.CreateTextfile(fn, false, false)

But I strongly recommend you to save the binary like the following:

Dim Stm
Set Stm = Server.CreateObject("Adodb.Stream")
    Stm.Type = 1 'adTypeBinary, to set binary stream
    Stm.Open
    Stm.Write oXMLHTTP.responseBody ' bytes of http response
    Stm.SaveToFile fn 'response saved as is
    Stm.Close
Set Stm = Nothing
Kul-Tigin
  • 16,728
  • 1
  • 35
  • 64