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