Request body encoding

3 posts, 0 answers
  1. Alex
    Alex avatar
    2 posts
    Member since:
    Jun 2015

    Posted 24 Dec 2015 Link to this post


    I have a flash application that sends flex messages to the server using POST request with application/x-amf content-type.

    following piece of code:

            private static void FiddlerApplication_BeforeRequest(Session oSession)
                if (oSession.oRequest.headers.ExistsAndEquals("Content-Type", "application/x-amf"))
                    Encoding enc = oSession.GetRequestBodyEncoding(); //we can use Encoding.UTF8..... doesn't matter - same result
                    string reqBody = enc.GetString(oSession.requestBodyBytes);
                    oSession.requestBodyBytes = enc.GetBytes(reqBody);

    WOW!!! In a response i see next:


    HTTP/1.1 200 OK
    Date: Fri, 25 Dec 2015 00:00:26 GMT
    Server: Apache
    Vary: Accept-Encoding
    Content-Encoding: gzip
    Content-Length: 275
    Connection: close
    Content-Type: application/x-amf;charset=utf-8

     and body:

    ..some content...//Unknown AMF type '-65'.Buf���/Client.Message.Encoding....


    So the server doesn' t like my harmless operation. But i can't understand. I think i did nothing with request body actually.

  2. Alex
    Alex avatar
    2 posts
    Member since:
    Jun 2015

    Posted 25 Dec 2015 Link to this post

    Oh, my mistake.

    For a safely convertion i have to use base64 encoding at least.

    Another way - convert bytes array into a HEX string for example.

  3. Eric Lawrence
    Eric Lawrence avatar
    832 posts

    Posted 28 Dec 2015 Link to this post

    Hi, Alex--

    I'm not sure if you're asking a question or not, but generally speaking, no, you can't treat a binary body like a string and expect that it won't be corrupted. oSession.requestBodyBytes is a byte array and should be kept as a byte array when interoperating with binary formats. The helper method oSession.GetRequestBodyAsString() should be used when you know that the body is plaintext.

    Eric Lawrence
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top