Server.UrlEncode()指定GBK编码
来源:互联网 发布:网络投资诈骗寻求帮助 编辑:程序博客网 时间:2024/06/05 00:37
问题:Server.UrlEncode(“你好”) 无法指定编码格式
解决方法:
方法一、调用Server.UrlEncode()之前加入
Response.ContentEncoding = System.Text.Encoding.GetEncoding(“GBK”)
方法二、在web.config中配置:
<configuration> <system.web> <globalization requestEncoding="GBK" responseEncoding="GBK" /> </system.web></configuration>
原因:
查看Server.UrlEncode()源码 (HttpServerUtility类):
public string UrlEncode(string s) { Encoding e = (_context != null) ? _context.Response.ContentEncoding : Encoding.UTF8; return HttpUtility.UrlEncode(s, e);}
而_context.Response.ContentEncoding的源码为
public Encoding ContentEncoding { get { if (_encoding == null) { // use LKG config because Response.ContentEncoding is need to display [config] error GlobalizationSection globConfig = RuntimeConfig.GetLKGConfig(_context).Globalization; if (globConfig != null) _encoding = globConfig.ResponseEncoding; if (_encoding == null) _encoding = Encoding.Default; } return _encoding; } set { if (value == null) throw new ArgumentNullException("value"); if (_encoding == null || !_encoding.Equals(value)) { _encoding = value; _encoder = null; // flush cached encoder if (_httpWriter != null) _httpWriter.UpdateResponseEncoding(); } }}
一目了然
阅读全文
0 0
- Server.UrlEncode()指定GBK编码
- 用Server.UrlEncode编码
- server.urlencode的反编码
- 关于HttpUtility.UrlEncode、UrlDecode,Server.UrlEncode、UrlDecode编码
- 关于HttpUtility.UrlEncode、UrlDecode,Server.UrlEncode、UrlDecode编码
- 关于HttpUtility.UrlEncode、UrlDecode,Server.UrlEncode、UrlDecode编码
- delphi GBK 以UTF-8的格式URLENCODE编码
- ASP 文件编码格式与 Server.URLEncode
- Server.UrlEncode、HttpUtility.UrlDecode不同编码
- mysql建表指定为gbk编码
- URLEncode 编码
- asp.net 基本的编码解码 Server.UrlEncode,Server.HtmlEncode
- Server.UrlEncode
- C# Server.UrlEncode/HttpUtility.UrlEncode 编码后生成的json 内容里空格变加号 解决办法
- Server.UrlEncode 与 HttpUtility.UrlEncode
- 关于HttpUtility.UrlEncode,Server.UrlEncode
- javascript中文编码/解析与C#ASP.NET中文编码/解析 C#: Server.UrlEncode() HttpUtility.UrlEncode() javascript: escape() encodeURI() encodeURICom
- python3-GBK编码字符串截取指定位置字串
- 设计模式之原型模式
- Android判断定位功能是否可用
- javascript中defer和async
- MyBatis三剑客
- pyspark 合并列与合并行
- Server.UrlEncode()指定GBK编码
- 小技巧实现修改input-file样式,代理上传
- git多人协作开发
- spring+springmvc+jpa+jsp 练习
- knowledge
- spring boot集成mybatis
- week_10_ ZigZag Conversion
- ubus实现进程间通信举例
- 深度学习资料汇总