使用encodeURI组件并在服务器端对其进行解码

Using encodeURIcomponent and decoding it on server side

本文关键字:解码 服务器端 encodeURI 组件 使用      更新时间:2023-09-26

我使用encodeURI组件向这样的服务器发送了一个url作为请求参数的一部分

  http://www.regis.edu/regisgpcd.asp?sctn=cpedcn&p1=ap&p2=EDFD&p3=cd3Dcd&_=1332612418587

这就是服务器所看到的:

http://www.regis.edu/regisgpcd.asp?sctn=cpedcn&p1=ap&p2=EDFD&p3=cd

尽管我之前用encodeURI组件再次将它插入数据库,但我得到了一个错误,即在数据库中找不到它。

这个url的格式如下,尽管我再次将其插入encodeURI组件之后。我猜mysql在将其插入列之前将其转换为常规类型。

 http://www.regis.edu/regisgpcd.asp?sctn=cpedcn&p1=ap&p2=EDFD&p3=cd

我该如何解决那个问题?知道吗?

这是我的插入代码:

$.ajax({
                    type : "GET",
                    url : '/tree/insertResult/?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title)+'&folder='+folderName+'&snippet='+encodeURIComponent(snippet),
                    cache : false,
                    success : function(res) {
                        if(res == "F")
                            notification("Operation Failed", "You have that bookmark in that folder!");
                        else{   
                            folderName = res;
                            notification("Operation Suceeded", "Bookmark has been created.");
                            updateFolderContent(url, title, folderName, snippet);//it is in _filetree_javascript.html.erb
                        }
                    },
                    error : function(x, y, z) {
                        alert(x.responseText);
                    }
                });
            }

这是我的提取代码:

$.ajax({
                type : "GET",
                url : '/tree/deleteResult/?title='+encodeURIComponent(title)+"&url="+encodeURIComponent(url), 
                cache : false,
                success : function(res) {
                    if(res == "F") //if F is returned from server it means "There is a folder with same name"
                        notification("Operation Failed", "Bookmark cannot be deleted! Sorry :(");   
                    else
                        notification("Operation Succeed", "Bookmark've been deleted.");     
                        deleteResult(domObj);
                },
                error : function(x, y, z) {
                    alert(x.responseText);
                }
            });
        }

我通过在服务器上解码字符串来解决这个问题。我在rails 中使用了CGI宝石

CGI::unescapeHTML(url)