生成多部分边界 [英] Generating multipart boundary

查看:123
本文介绍了生成多部分边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本,该脚本将文件上传到需要多个部分请求的cgi脚本,例如HTML页面上的表单. boundary是唯一的令牌,用于注释请求正文中的文件内容.这是一个示例正文:

I'm writing a script that uploads a file to a cgi script that expects a multipart request, such as a form on a HTML page. The boundary is a unique token that annotates the file contents in the request body. Here's an example body:

--BOUNDARY
Content-Disposition: form-data; name="paramname"; filename="foo.txt"
Content-Type: text/plain

... file contents here ...
--BOUNDARY--

出于明显的原因,boundary不能出现在文件内容中.

The boundary cannot be present in the file contents, for obvious reasons.

我应该怎么做才能创建一个唯一的边界?我应该生成一个随机字符串,检查它是否在文件内容中,如果存在,请生成一个新字符串,冲洗并重复直到我拥有唯一的字符串为止?还是相当随机的令牌"(例如,时间戳,进程ID等的组合)就足够了?

What should I do in order to create an unique boundary? Should I generate a random string, check to see if it is in the file contents, and if it is, generate a new, rinse and repeat, until I have a unique string? Or would a "pretty random token" (say, combination of timestamp, process id, etc) be enough?

推荐答案

如果使用足够随机的东西(例如GUID),则不需要搜索有效载荷来检查边界的别名.像这样:-

If you use something random enough like a GUID there shouldn't be any need to hunt through the payload to check for an alias of the boundary. Something like:-

---- == NextPart_3676416B-9AD6-440C-B3C8-FC66DDC7DB45
标头:....

----=NextPart_3676416B-9AD6-440C-B3C8-FC66DDC7DB45
Header:....

有效载荷
---- = NextPart_3676416B-9AD6-440C-B3C8-FC66DDC7DB45-

Payload
----=NextPart_3676416B-9AD6-440C-B3C8-FC66DDC7DB45--

这篇关于生成多部分边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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