在PHP / Drupal中停止自动URL解码

时间:2011-03-30 23:07:20

标签: php jquery drupal

我将自定义XML数据从jQuery发送到Drupal / PHP,如下所示:

$.ajax({
            type: 'POST',       
            url: this.href,

            success: function(data){ 

                alert('Form is successfully saved');


            },
            error:function(XMLHttpRequest, textStatus,  errorThrown){
                alert("Error");

            },

            data: 'myxml='+ mydata 
        });

我的XML标记包含URL,因此我对它们进行编码,在进行AJAX调用之前,数据看起来有点像这样:

mydata="<txtLinkLocation>http%3A%2F%2Fportal.cubewerx.com%2Fcubewerx%2Fcubeserv%2Fcubeserv.cgi%3FCONFIG%3Dhaiti%26SERVICE%3DWFS%26DATASTORE%3DOSM%26request%3DGetCapabilities</txtLinkLocation>";

并且,在PHP中,我获得了收到的数据,并将其存储如下:

$receivedXML = $_POST['myxml'];

现在,包含$ receivedXML的内容如下:

<txtLinkLocation>http://portal.cubewerx.com/cubewerx/cubeserv/cubeserv.cgi?CONFIG=haiti&SERVICE=WFS&DATASTORE=OSM&request=GetCapabilities</txtLinkLocation>

我的问题是为什么此字符串中的URL会被自动解码?为什么会这样?我不希望对通过AJAX调用发送的数据执行任何自动操作。如何阻止这种行为?我觉得我在这里错过了一些基本概念......

2 个答案:

答案 0 :(得分:2)

$ _ POST数据以与$ _GET相同的方式发送到服务器。它必须被发送urlencoded否则它可能会破坏。这意味着默认情况下,PHP会解码urlencodes,因为它希望数据是urlencoded。

答案 1 :(得分:1)

PHP默认解码$ _GET和$ _REQUEST数据,请参阅the note in urldecoding on auto-encoding server variables。事实证明$ _POST也是如此。

解决方案:如果您希望对数据进行编码,请再次urlencode()您的数据。