之前新项目用flash上传图片数据以及其他一些字段,由于之前的开源库不够好,所以自己重写了一个AS3 form http request builder。
view more at:https://github.com/cos2004/FormRequestBuilder
用途:用于flash同时发送图片数据和一些其他值对的时候,此小工具可以方便构造一个标准的http form请求。
顺便讲一点http的知识:
Content-Type: multipart/form-data; boundary=Rm9ybVJlcXVlc3RCdWlsZGVyQnljb3MyMDA0
头部的boundary需要指定,可以是任意的随机字符串,即实体数据分隔符
cookie与下面的实体内容有一个换行,然后是分割线,此分割线比之前Content-Type指定的分割线前面多两个横线-;Content-Disposition与数据内容直接有两个换行。乱码部分为图片流。
实体结束部分的分割线后面要再加两个-
================================分割线===============================
另外,在高级浏览器里,用javascript里面也可以构造类似的http请求,构造方法类似,用xhr发送。在高级浏览器里用FileReader读取图片数据,再拼一下其他字段的数据,用setRequestHeader设置一下Content-Type,然后send。但现在用js处理图片数据的情况不多,而且浏览器的支持情况也很有限,所以在js里构造类似的请求的应用场景不多。
==================================================
作者:绿色花园
出处: http://www.cnblogs.com/cos2004/archive/2012/12/03/2799282.html
==================================================