链接缩写与希伯来字符

时间:2017-09-05 17:52:56

标签: xml vba vb6

我正在使用以下功能来成功缩短长链接。我的问题是它无法正确呈现URL变量中使用的希伯来字符。看起来我应该在编码函数中添加一些东西,但我不熟悉编码问题

Function GetShortURL(url As String, index As Integer) As String

url = URLEncode(url)
Dim xml As Object
Set xml = CreateObject("MSXML2.XMLHTTP.6.0")

Select Case index
 Case 0 ' tinyURL
      xml.Open "POST", "http://tinyurlcom/api-create.php?url=" & url, False
      xml.Send



      End Select

 GetShortURL = xml.ResponseText

  End Function

 Public Function URLEncode( _
 StringVal As String, _
 Optional SpaceAsPlus As Boolean = False _
 ) As String

    Dim StringLen As Long: StringLen = Len(StringVal)

 If StringLen > 0 Then
 ReDim result(StringLen) As String
 Dim i As Long, CharCode As Integer
 Dim Char As String, Space As String

 If SpaceAsPlus Then Space = "+" Else Space = "%20"

 For i = 1 To StringLen
      Char = Mid$(StringVal, i, 1)
      CharCode = Asc(Char)
      Select Case CharCode
           Case 97 To 122, 65 To 90, 48 To 57, 45, 46, 95, 126, 128
                result(i) = Char
           Case 32
                result(i) = Space
           Case 0 To 15
                result(i) = "%0" & Hex(CharCode)
           Case Else
                result(i) = "%" & Hex(CharCode)
      End Select
 Next i
 URLEncode = Join(result, "")

 End If
 End Function

0 个答案:

没有答案