【问题标题】:CodeIgniter throwing "The URI you submitted has disallowed characters..." and I can't see what's causing itCodeIgniter 抛出“您提交的 URI 包含不允许的字符...”,我看不出是什么原因造成的
【发布时间】:2015-11-15 04:15:25
【问题描述】:

我从 CodeIgniter 收到此错误:

您提交的 URI 包含不允许的字符。...

在这个 JSON 字符串上:

{"from":"feedback@myapp.com","to":"support@myapp.com","cc":"myadmin@ myapp.com, myfellowadmin@myapp.com","subject":"FROM APP: User Feedback","message":"FROM USER: testy.testerson@testme.com:\nHere's a test comment"}

当我尝试使用以下代码对其进行编码时:

URLreadyJSON = encodeURIComponent(JSON.stringify(JsonObj));

JsonObj就是上面提到的JSON字符串。)

URLreadyJSON 解析为:

https://127.0.0.1/Xhr/email/%7B%22from%22%3A%22feedback%40myapp.com%22%2C%22to%22%3A%22support%40myapp.com%22%2C%22cc%22%3A%22myadmin%40myapp.com%2C%20myfellowadmin%40myapp.com%22%2C%22subject%22%3A%22FROM%20APP%3A%20User%20Feedback%22%2C%22message%22%3A%22FROM%20USER%3A%20testy.testerson%40testme.com%3A%5CnHere's%20a%20test%20comment%22%7D

相关代码:

function sendFeedback() {
    JsonObj = { 
        'from': 'feedback@myapp.com',
        'to': 'support@myapp.com',
        'cc': 'myadmin@myapp.com, myfellowadmin@myapp.com',
        'subject': 'FROM APP: User Feedback',
        'message': 'FROM USER: ' + $('#feedback_email').val() + ":\n" + $('#feedback_message').val()
    }

    URLreadyJSON = encodeURIComponent(JSON.stringify(JsonObj));

    $.ajax({
        url: "/Xhr/email/" + URLreadyJSON,
        type: 'POST',
        dataType: 'json',
        success: function(data) {
            $('#feedback_feedback').text(data.message);
            if(!data.error) {
                $("#feedback_popup").popup("open");   // Open confirm popup
                $('#feedback_message').text('');      // Clear original message input
                $('#feedback_email').text('');        // Clear sender email
                setTimeout(function() { $("#feedback_popup").popup("close") }, 2500);
            }
        },
        fail: function(data) {
            console.log("FAIL");
            console.log(data);
        }
    });
}

最后,在我的 CodeIgniter 配置文件中,我将 permitted_uri_chars 设置为:

$config['permitted_uri_chars'] = 'a-z 0-9~%.,":_?&=;}{@-';

我已经检查了我能找到的所有解决这个错误的方法(并且有一些),并结合了这些建议,但没有成功。我一定是错过了什么,希望有人能看到那是什么。

【问题讨论】:

标签: php codeigniter uriencoding


【解决方案1】:

尝试改变:-

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\=';

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\=+';

【讨论】:

    【解决方案2】:
    function sendFeedback() {
    JsonObj = { 
        'from': 'feedback@myapp.com',
        'to': 'support@myapp.com',
        'cc': 'myadmin@myapp.com, myfellowadmin@myapp.com',
        'subject': 'FROM APP: User Feedback',
        'message': 'FROM USER: ' + $('#feedback_email').val() + ":\n" + $('#feedback_message').val()
    }
    
    $.ajax({
        url: "/Xhr/email/",
        type: 'POST',
        dataType: 'json',
        data : JsonObj, // add this
        success: function(data) {
            $('#feedback_feedback').text(data.message);
            if(!data.error) {
                $("#feedback_popup").popup("open");   // Open confirm popup
                $('#feedback_message').text('');      // Clear original message input
                $('#feedback_email').text('');        // Clear sender email
                setTimeout(function() { $("#feedback_popup").popup("close") }, 2500);
            }
        },
        fail: function(data) {
            console.log("FAIL");
            console.log(data);
        }
    });
    

    }

    服务器端:

    $from: $this->input->post('from',true);
    $to: $this->input->post('to',true);
    $cc: $this->input->post('cc',true);
    $subject: $this->input->post('subject',true);
    $message: $this->input->post('message',true);
    

    【讨论】:

      猜你喜欢
      • 2015-06-29
      • 1970-01-01
      • 2015-07-10
      • 2023-03-20
      • 2021-03-14
      • 1970-01-01
      • 2018-11-11
      • 2019-11-17
      • 1970-01-01
      相关资源
      最近更新 更多