javascript urlencoding problem
by "Andy Innes" <innax(at)icon.co.za>
|
Date: |
Wed, 8 May 2002 18:32:36 +0200 |
To: |
<hwg-techniques(at)hwg.org> |
References: |
services |
|
todo: View
Thread,
Original
|
|
Hi Guys
I am getting a list of stock prices from a server in text format.
There is an asp file being triggered every 15 minutes to urlencode the file
and write it to our local server as a url-encoded text file.
I need the script in the asp file to ignore the "=" symbol and make it an
"=" in the resulting url-encoded file.
If anyone could help, I'd really appreciate it: here's the code:
<%
'**** Begin Subs & Functions
' Encode a number from 0..15 to a single hex digit
Function HexChar(ByVal i)
If i < 10 Then
HexChar = Chr(i+Asc("0"))
Else
HexChar = Chr(i-10+Asc("A"))
End If
End Function
' Encode the control and punctuation characters in a string to %xx hex
values
Function URLEncode(ByVal s)
Dim result, ch
Do While Len(s) > 0
ch = Asc(s)
s = Right(s, Len(s)-1)
If (ch >= Asc("a") And ch <= Asc("z")) Or (ch >= Asc("A") And ch <=
Asc("Z")) Or (ch >= Asc("0") And ch <= Asc("9")) Then
result = result & Chr(ch)
ElseIf ch = Asc(" ") Then
result = result & "+"
Else
'result = result & "*" & ch
'result = result & "!" & (ch/16) & (ch mod 16)
result = result & "%" & HexChar(Int(ch/16)) & HexChar(ch Mod 16)
End If
Loop
URLEncode = result
End Function
Function ReportFileStatus(filespec)
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = true
Else
msg = false
End If
ReportFileStatus = msg
End Function
Function DeleteAFile(filespec)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.DeleteFile(filespec)) Then
DeleteAFile = True
Else
DeleteAFile = False
End If
End Function
Sub CreateFile(filespec)
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(filespec, True)
MyFile.Close
End Sub
Sub OpenTextFileTest(filespec, content)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filespec, ForWriting, True)
f.Write content
f.Close
End Sub
'**** End Subs & Functions
'**** this reads data
dim http, doc, indx, toIndx, prc, bid, offer
set http = Server.CreateObject("Microsoft.XMLHTTP")
http.open "GET", "http:the remote server textfile.price", false
http.send
doc = http.responseText
'**** this encodes the data
message = ("message="+URLEncode(doc)+"&confirm=2")
'**** this writes the data to the txt file
Dim filespec
filespec = "d:\inetpub\wwwroot\mysite.com\www\Feed\shares.txt"
'Create File, if file exists overwrite it.
CreateFile(filespec)
Call OpenTextFileTest(filespec, message)%>
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA