您的位置:首页 > 其它

CI中REST URL含有中文怎么处理(报错:The URI you submitted has disallowed characters)

2015-01-28 21:03 183 查看
解决方法:

客户端在发送GET URL请求的时候,将含有中文的URL编码即可

比如:

原始:http://localhost/qk/rest/user_album_api/get_user_albums_by_desc/album_desc/风景/page_num/1/page_size/3

URL转码 http://tool.oschina.net/encode?type=4
结果是:http://localhost/qk/rest/user_album_api/get_user_albums_by_desc/album_desc/%E9%A3%8E%E6%99%AF/page_num/1/page_size/3

在服务器端,再进行对该编码的字段进行解码即可,用PHP函数string urldecode ( string
$str
)

urldecode

(PHP 4, PHP 5)

urldecode — 解码已编码的 URL 字符串

说明

string urldecode ( string
$str
)
解码给出的已编码字符串中的任何 %##。 加号('+')被解码成一个空格字符。

参数

str

要解码的字符串。

返回值

返回解码后的字符串。

范例

Example #1 urldecode() 示例

<?php
$query = "my=apples&are=green+and+red";

foreach (explode('&', $query) as $chunk) {
$param = explode("=", $chunk);

if ($param) {
printf("Value for parameter \"%s\" is \"%s\"<br/>\n", urldecode($param[0]), urldecode($param[1]));
}
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: