码迷,mamicode.com
首页 > 其他好文 > 详细

AS3 Post 参数和ByteArray的方法及服务器端接收

时间:2015-05-25 19:59:48      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:

as端: (form表单形式)
req.method = URLRequestMethod.POST;
var reqHeader:URLRequestHeader = new URLRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.requestHeaders.push(reqHeader);
........ -->by; 
var param:URLVariables = new URLVariables();
var encoder:Base64Encoder = new Base64Encoder();
encoder.encodeBytes(by);
param.data = encoder.toString();
param.content = "上面这个by是二进制数组,如图片等"; 
req.data = param;
UrlLoader.load(URLRequest); 


C#端接收:

System.IO.Stream s = System.Web.HttpContext.Current.Request.InputStream;
int count = 0;
byte[] buffer = new byte[1024];
StringBuilder builder = new StringBuilder();
while ((count = s.Read(buffer, 0, 1024)) > 0)
{
        builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
}
........
urlStr = "....."
string text= System.Web.HttpUtility.UrlDecode(urlStr, System.Text.Encoding.UTF8);
byte[] bpath = Convert.FromBase64String(text);
string filePath = "图片123.jpg";
Stream stream = new MemoryStream(bpath);
using (Bitmap b = new Bitmap(stream))
{
     b.Save(filePath, ImageFormat.Jpeg);


由于服务器端从URL取出的字符串urlStr 是经过URL编码的,所以需要使用 System.Web.HttpUtility.UrlDecode进行解码成UTF-8 
 

AS3 Post 参数和ByteArray的方法及服务器端接收

标签:

原文地址:http://www.cnblogs.com/yhf286/p/4528565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!