开发者

How to send a "multipart/related" content type in Actionscript?

If I want to send the following format body in actionscript through http Post:开发者_Python百科

Content-Type: multipart/related; boundary="END_OF_PART"
Content-Length: 423478347
MIME-version: 1.0

Media multipart posting
--END_OF_PART
Content-Type: application/atom+xml

<entry xmlns='http://www.w3.org/2005/Atom'>
  <title>plz-to-love-realcat.jpg</title>
  <summary>Real cat wants attention too.</summary>
  <category scheme="http://schemas.google.com/g/2005#kind"
    term="http://schemas.google.com/photos/2007#photo"/>
</entry>
--END_OF_PART
Content-Type: image/jpeg

...binary image data...
--END_OF_PART--

How can I write the actionscript to send the "multipart/related" content type.

Please advice. Thanks.


One thing that might help is using something like the AS3 HTTPClient library - they have helper methods for all sorts of request/response header manipulation that plain AS3 won't do. You can find it here: http://code.google.com/p/as3httpclientlib/

Doing anything beyond simple HTTP get/post is always a pain in Flash, and multipart POST is particularly tricky. If that httpclient doesn't do what you need let me know and I have one more utility I used to do this in the past. I can dig that up for you if you need it, just let me know!

Hope that helps, myk


Inspirit's MultipartURLLoader will probably help. Haven't used it for multipart/related, but it has lots of useful functionality for adding files with different content types.

For example, you can add files with different content types using the addFile function :

addFile(fileContent:ByteArray, fileName:String, dataField:String = 'Filedata', contentType:String = 'application/octet-stream')

It seems to use multipart/form-data when it sends :

urlRequest.requestHeaders.push( new URLRequestHeader('Content-type', 'multipart/form-data; boundary=' + getBoundary()) );

but you could easily extend this to use multipart/related.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜