Skip to main content

Special characters in REST request


I am developing an API using CodeIgniter, and Phils RESTserver. I am trying to send a POST request containing special characters, but the string is not added to the database.



CodeIgniter also says that lastname is required (that it is not present in the string). Why?



I am using this format:




application/x-www-form-urlencoded



This is my string:




firstname=Andrew&lastname=Åsberger



It is very important that I can use special characters for internationalization.



Thankful for all input!


Source: Tips4allCCNA FINAL EXAM

Comments

  1. You should URI-encode each name and value. Hopefully the client and server code will both agree that UTF-8 should be used for encoding the octets of characters outside of the US-ASCII range (since earlier URI-encoding standards weren't specific and there is legacy code out there that tries other encodings), so your example becomes:

    firstname=Andrew&lastname=%C3%85sberger

    Just like it would in the query portion of a URI used with a GET.

    ReplyDelete
  2. It seems like you are having an encoding issue. You need to make sure that you are using UTF8 from end to end: client (browser), server (PHP), db connection and db. I assume your db table(s) are already UTF8, but what many forget is the connection to the database. Right after you connect to the database, you should run the "query" SET NAMES UTF8. Not sure if CodeIgniter uses the db connection to escape characters.

    I don't use CodeIgniter, but if it's not using the proper encoding, then double-byte characters get expanded out into 2 characters. For example, if you running urlencode('Å') returns %C3%85, not %C5. This is actually a SQL injection method. If one of the characters it "decodes" to is a ' or ", then there is a quoting issue/vulnerability. This could cause CodeIgniter to evaluate the string incorrectly.

    Finally, are you doing your POST through javascript? Javascript does not support UTF8 encoding, so it causes some problems depending on how you POST. You can use javascript to POST a html form, but you can run into problems when you try to do an ajax post using strings you make yourself. Although unescape( encodeURIComponent( s ) ) supposedly works.

    ReplyDelete
  3. Once i had a similar issue while inserting products with special chars in name into cart and in creating my urls

    Not sure, but it may be helpful from another point of view. I also had added a my_url_helper in addition for my project to handle urls. mb_string handles char replacements very well. Sorry for my bad language. :(

    File: application/config.php

    /*
    |--------------------------------------------------------------------------
    | Allowed URL Characters
    |--------------------------------------------------------------------------
    |
    | This lets you specify with a regular expression which characters are permitted
    | within your URLs. When someone tries to submit a URL with disallowed
    | characters they will get a warning message.
    |
    | As a security measure you are STRONGLY encouraged to restrict URLs to
    | as few characters as possible. By default only these are allowed: a-z 0-9~%.:_-
    |
    | Leave blank to allow all characters -- but only if you are insane.
    |
    | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
    |
    */

    //This is not default, its modified for turkish chars
    $config['permitted_uri_chars'] = 'a-üöçşığz A-ÜÖÇŞİĞZ 0-9~%.:_\-';

    ReplyDelete
  4. I'm not particularly familiar with CodeIgniter; however, this:

    Codeigniter seems to break $_POST of '£' character (Pound)

    ...might be relevant. That is, the problem might be in your server stack, not your code or framework! Otherwise, here are some additional links that address other areas of concern w.r.t. CodeIgniter and UTF-8:

    http://hash-bang.net/2009/02/utf8-with-codeigniter/

    http://philsturgeon.co.uk/blog/2009/08/UTF-8-support-for-CodeIgniter

    Hope this helps.

    ReplyDelete
  5. It's not MongoDb as you aren't getting what you need from the post.

    I'm almost entirely certain it is your encoding details, not matching from client to server.

    Others' suggestions of standardizing on UTF-8 is good practice, but if you didn't want to, just make sure you are using an encoding schema that works with your chars and is used both client-side and server-side.

    I'm not an expert at PHP, but you are getting normal characters (B) plus special characters (& and %) and escaped normal characters (%26)... but not escaped special chars like %C3%85.

    Update some more info about how you are posting to the server and I'll elaborate more.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex