This is a migrated thread and some comments may be shown as answers.

Request body encoding

2 Answers 1593 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 25 Dec 2015, 12:31 AM

Hi,

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:

Headers:

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 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 25 Dec 2015, 03:22 PM

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.

0
Eric Lawrence
Telerik team
answered on 28 Dec 2015, 03:44 PM
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.

Regards,
Eric Lawrence
Telerik
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
Tags
Fiddler Classic
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Eric Lawrence
Telerik team
Share this question
or