开发者

C# .net equivilent of HTTP_RAW_POST_DATA?

Want to mimic php code in c# .

I want to Capture raw image data posted from the following Flash Actionscript:

   function onSaveJPG(e:Event):void{
        var myEncoder:JPGEncoder = new JPGEncoder(100);
        var byteArray:ByteArray = myEncoder.encode(bitmapData);

        var header:URLRequestHeader = new URLR开发者_开发知识库equestHeader("Content-type", "application/octet-stream");

        var saveJPG:URLRequest = new URLRequest("save.aspx");
        saveJPG.requestHeaders.push(header);
        saveJPG.method = URLRequestMethod.POST;
        saveJPG.data = byteArray;

        var urlLoader:URLLoader = new URLLoader();
        urlLoader.addEventListener(Event.COMPLETE, sendComplete);
        urlLoader.load(saveJPG);

        function sendComplete(event:Event):void{
            warn.visible = true;
            addChild(warn);
            warn.addEventListener(MouseEvent.MOUSE_DOWN, warnDown);
            warn.buttonMode = true;
        }

    }

On Page load of Save.aspx.cs page. Here is the the PHP code i'm trying to mimic -

if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){
    $jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
    $img = $_GET["img"];
    $filename = "images/poza_". mktime(). ".jpg";
    file_put_contents($filename, $jpg);
} else{
    echo "Encoded JPEG information not received.";
}

Any pointers and suggestion would be much appreciated. Thanks !


Would something like this work for you?

byte[] data = Request.BinaryRead(Request.TotalBytes);


You should be able to get the raw HTTP post data by accessing Request.InputStream. Read from the stream and write it into a file.

EDIT: Do use James' suggestion of Request.BinaryRead. For writing, you can use File.WriteAllBytes(filename, data). The $_GET equivalent in asp.net is Request.QueryString.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜