我可以将 UTF8 编码的字符串传递给 Web 服务吗?
更新:
Function EncodeToUTF(ByVal toEncode As String) As String
Dim utf8 As New UTF8Encoding()
Dim encodedBytes As Byte() = utf8.GetBytes(toEncode)
Dim returnValue As String = utf8.GetString(encodedBytes)
returnValue = HttpUtility.UrlEncode(returnValue)
Return returnValue
End Function
然后在网络服务器上解码?问题是 XML Web Service 解析器正在从我的字符串中删除 CR。
然后在服务器端解码:
Function DecodeFromUTF8(ByVal encodedData As String) As String
Dim utf8 As New UTF8Encoding()
Dim returnValue As String = HttpUtility.UrlDecode(encodedData)
Dim encodedDataAsBytes As Byte() = utf8.GetBytes(returnValue)
returnValue = utf8.GetString(encodedDataAsBytes)
Return returnValue
End Function
这里的 returnValue 仍然是编码的。