什么规则适用于MIME边界? [英] What rules apply to MIME boundary?

查看:757
本文介绍了什么规则适用于MIME边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您编写MIME时,您将消息的不同块与特定边界分开。我出于某种原因找不到任何解释这个边界的文档,但是这是我从示例中收集的内容:


  1. 边界可以是任何一串字母和数字,我即d29a0c638b540b23e9a29a3a9aebc900aeeb6a82。


  2. 没有生成边界的规则,你可以md5sum你心爱的名字,你走了,你有您的边界。


  3. 如果您要通过HTTP发送MIME,则必须添加标题Content-Type,指明您执行的操作,以及您的边界内容标题可能如下所示:



    multipart / form-data; boundary = d29a0c638b540b23e9a29a3a9aebc900aeeb6a82


  4. 在邮件正文中,边界应以 - 开头,如:



    - d29a0c638b540b23e9a29a3a9aebc900aeeb6a82


但是遵循这些规则(以及这个有用的答案)我无法生成服务器可以接受的POST查询。我错过了什么吗?我搞错了吗?

解决方案

边界的语法是:


  boundary:= 0 * 69< bchars> bcharsnospace 
bchars:= bcharsnospace /
bcharsnospace:= DIGIT / ALPHA /'/(/)/
+/_/, / - /。 /
//:/=/?


以及多部分实体的主体具有语法(仅限重要部分):


  multipart-body:= [preamble CRLF] 
dash-boundary transport-padding CRLF
body-part * encapsulation
close-delimiter transport-padding
[CRLF结语]
dash-boundary:= - boundary
encapsulation:= delimiter transport-padding
CRLF body-part
分隔符:= CRLF破折号边界
close-delimiter:=分隔符 -




前面的 - 对于邮件中使用的每个边界和尾随的 - <是必需的/ code>对于结束边界( close-delimiter )是必需的。因此,具有边界作为边界的三个正文部分的多部分主体可以如下所示:

   - 边界
1.正文部分
- 边界
2.正文部分
- 边界
3.正文部分
- 边界 -


When you are writing MIME, you separate different chunks of your message with a certain boundary. I failed for some reason to find any documentation explaining this boundary, but here's what I gathered from examples:

  1. Boundary can be any string of letters and numbers, i. e. "d29a0c638b540b23e9a29a3a9aebc900aeeb6a82".

  2. There are no rules for generating the boundary, you can just md5sum the name of your beloved, and here you go, you've got your boundary.

  3. If you are sending MIME over HTTP, you must add a header "Content-Type" specifying that you do, and your boundary, contents of a header may look like this:

    multipart/form-data; boundary=d29a0c638b540b23e9a29a3a9aebc900aeeb6a82

  4. In the body of your message, the boundary should be preceded with "--", like:

    --d29a0c638b540b23e9a29a3a9aebc900aeeb6a82

But following these rules (and this helpful answer) I failed to generate POST query that server would accept. Am I missing something? Did I get something wrong?

解决方案

The syntax of a boundary is:

 boundary := 0*69<bchars> bcharsnospace
 bchars := bcharsnospace / " "
 bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" /
                  "+" / "_" / "," / "-" / "." /
                  "/" / ":" / "=" / "?"

And the body of a multipart entity has the syntax (only the important parts):

 multipart-body := [preamble CRLF]
                   dash-boundary transport-padding CRLF
                   body-part *encapsulation
                   close-delimiter transport-padding
                   [CRLF epilogue]
 dash-boundary := "--" boundary
 encapsulation := delimiter transport-padding
                  CRLF body-part
 delimiter := CRLF dash-boundary
 close-delimiter := delimiter "--"

The preceeding -- is mandatory for every boundary used in the message and the trailing -- is mandatory for the closing boundary (close-delimiter). So a multipart body with three body-parts with boundary as boundary can look like this:

--boundary
1. body-part
--boundary
2. body-part
--boundary
3. body-part
--boundary--

这篇关于什么规则适用于MIME边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆