经典的 Asp 到 Asp.Net urlEncoding 问题
我正在使用 Web 服务将信息从一堆旧的 .asp 页面传递到数据库。 问题是使用 httpGet 时,我需要对信息进行编码,以便可以安全地传递。
一切都像一场梦,除了斯堪的纳维亚字母(例如 ä ö 和 å)显示为正方形。 现在我什至不知道这是否与公司IIS语言设置有关(无法触及它们)或其他什么,但我想知道是否有一种方法可以强制asp页面使用特定的编码,并且然后强制 asp.net Web 服务使用相同的字符集进行解码,没有任何类型的服务器设置,有机会将它们全部混合起来?
我试图环顾四周,但没有找到任何明确的示例来说明如何做到这一点。 请回复简单一点,我只是在这里实习的初学者。 谢谢您的帮助!
编辑: 道歉。 没有包含代码,因为它太简单了,我认为它不会透露任何内容。 这里:
.asp
function loginfo()
Dim text
text = "ääböö"
text = Server.URLENCODE(text)
message = "http://server1/logger_webservice/service.asmx/test_Event?" & _
"userID=" & userID
Set objRequest = Server.createobject("MSXML2.XMLHTTP")
With objRequest
.open "GET", message, False
.setRequestHeader "Content-Type", "text/xml"
.send
End With
loginfo = objRequest.responseText
end function
Web 服务器:
<WebMethod()> _
Public Function test_Event(ByVal userId As String) As Boolean
Dim kirj As StreamWriter
kirj = File.CreateText("C:\Inetpub\server1\Logger_WebService\test_logEvent.txt")
userId = Server.UrlDecode(userId)
kirj.WriteLine("userId = " & userId)
kirj.Close()
kirj.Dispose()
End Function
无论如何,感谢您的帮助。 我会进一步研究这个问题,但像往常一样,压力和匆忙迫使我继续前进。 我编写了一个简单的代码来手动加密最常用的斯堪的纳维亚字母,并在网络服务器中解密它们。 到目前为止工作正常,我只是希望不会有任何并发症发生。 无论如何,我只想要基本的芬兰语字母 ä、ö 和 å。 :)
我只是认为有一些简单的方法可以强制编码为我找不到的特定字符集。 我自己寻找信息的能力往往很差。
I'm using a web service for passing information from a bunch of old .asp pages to a database. Problem is that using httpGet, I need to encode the info so it can be safely passed.
Everything works like a dream, save for the fact that scandinavian letters such as ä ö and å for example come out as squares. Now I don't even know whether this has to do with the company IIS language settings (can't touch them) or something, but I'm wondering if there's a way to force the asp-page to use a specific encoding, and then force the asp.net web service to decode with the same character-set, without any kind of server settings inbetween getting the chance to mix it all up?
I tried to look around, but didn't find any clear-cut examples of exactly how you can do this. Please keep the replies simple, I'm just a beginner on internship here. Thanks for the help!
Edit:
Apologies. Didn't include the code because it was so simple I didn't think it'd reveal anything anyway. Here:
.asp
function loginfo()
Dim text
text = "ääböö"
text = Server.URLENCODE(text)
message = "http://server1/logger_webservice/service.asmx/test_Event?" & _
"userID=" & userID
Set objRequest = Server.createobject("MSXML2.XMLHTTP")
With objRequest
.open "GET", message, False
.setRequestHeader "Content-Type", "text/xml"
.send
End With
loginfo = objRequest.responseText
end function
web server:
<WebMethod()> _
Public Function test_Event(ByVal userId As String) As Boolean
Dim kirj As StreamWriter
kirj = File.CreateText("C:\Inetpub\server1\Logger_WebService\test_logEvent.txt")
userId = Server.UrlDecode(userId)
kirj.WriteLine("userId = " & userId)
kirj.Close()
kirj.Dispose()
End Function
Anyway, thanks for help. I'll be looking into this more but as usual, stress and rush is forcing me to move on. I wrote a simple code to encrypt the most used scandinavian letters manually, and decrypted them in the web server. Works fine so far, I just hope there aren't any complications alter on. Just wanted the basic Finnish letters ä, ö and å anyway. :)
I just thought there was some easy method to force the encoding to a specific charset that I just couldn't find. Tend to be terrible at finding information on my own.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最近提出的这个问题进一步阐明了 UrlEncoding 的此类问题:
/questions/696659 /why-is-this-appearing-in-my-c-strings-194163
它可能对您自己或其他遇到此问题的人有用。
This recent question that I asked sheds further light on this type of issue with UrlEncoding:
/questions/696659/why-is-this-appearing-in-my-c-strings-194163
It may prove useful to yourself or others hitting this problem.
如果不深入研究代码,我无法给您一个“这里位于 X 行”的答案,但您正在处理的问题是编码问题之一。 字符串编码有多种方式,从 ASCII 到 UTF-8 再到完整的 Unicode。 这意味着如果强制使用完整的 unicode 编码可能会解决您的问题。
为此,您可以使用编码显式创建流(和/或读取器/写入器)。 对于不同类型的对象,方法是不同的,并且不知道你的代码,我无法给你明确的答案。
然而,使用 ASP,您可能仍然会得到垃圾。 而且,自从我使用经典 ASP 以来已经很久了,我必须在那里挖掘才能找到答案。 幸运的是,听起来您有办法测试 ASP 以确保正确的字符通过,因此请进行测试。 如果有效,请关注 Web 服务。
Without digging into the code, I cannot give you a "here it is on line X" answer, but the issue you are dealing with is one of encoding. There are multiple ways of encoding strings, from ASCII to UTF-8 to full blown Unicode. What this means is Ifforcing full unicode encoding might solve your problem.
To do this, you can explicitly create your streams (and/or readers/writers) with an encoding. The method is different for different types of objects, and not knowing your code, I cannot give you an explicit answer.
With ASP, you may still be getting garbage, however. And, it has been so long since I played with classic ASP, I would have to dig to get an answer there. Fortunately, it sounds like you have a way to test the ASP to ensure the correct characters are coming through, so test. If it works, focus on the web service.