Apache基准测试Multipart/Form-Data [英] Apache benchmark multipart/form-data

查看:577
本文介绍了Apache基准测试Multipart/Form-Data的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在apache基准测试发布文件中遇到了一个奇怪的问题.

i'm facing a strange problem with apache benchmark post file.

我需要强调处理文件上传的功能.因此,我在Google上进行了搜索,并找到了描述如何正确构建Post文件的帖子.其内容如下:

I need to stress a feature that handles file upload. So, I googled about, and found a post describing how to build a post file properly. Its contents looks like:

--1234567
Content-Disposition: form-data; name="user_id"

3
--1234567
Content-Disposition: form-data; name="file"; filename="cf_login.png"
Content-Type: image/png

[base64 encoded file content]
--1234567--

ab线是这样的:

$ ab -c 1 -n 5 -v 4 -T 'multipart/form-data; boundary=1234567' -p post_file.txt http://localhost:3000/files

当ab发出请求时,生成的标头如下:

When ab make the requests the generated header is the following:

INFO: POST header == 
---
POST /files.json/ HTTP/1.0
Content-length: 229
Content-type: multipart/form-data; boundary=simpleboundary
Host: localhost:3000
User-Agent: ApacheBench/2.3
Accept: */*


---
LOG: header received:
HTTP/1.1 500 Internal Server Error 
Content-Type: text/html; charset=utf-8
Content-Length: 13265
X-Request-Id: 9ad57d19cd71886a1bb817d00fac651b
X-Runtime: 0.015504
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
Date: Tue, 25 Sep 2012 13:54:29 GMT
Connection: close

期望的回报是一个提高params.inspect,让我看看数据是否正在到达另一端.如果删除边界,我可以看到在params中接收到的数据,但这不是我想要的.我想上传文件.

The expected return is a raise params.inspect, that let me see if the data is arriving to the other side. If I remove the boundary I can see data received in params, but this is not what I want. I want to get a file upload.

有人给小费吗?我将非常感激.

Anyone has a tip? I will really appreciate it.

推荐答案

我找到了答案,并决定与您分享.

I found the answer, and decided to share with you.

在处理过后的文件后,我决定创建一个PHP脚本,仅输出$ _FILES和$ _REQUEST变量以查看文件是否正确构建.确实,apache可以完美地接收文件,并且我可以看到文件数据和其他请求参数.

After some struggle with the post file, I decided to create a php script just to output the $_FILES and $_REQUEST variables to see if the file was built correctly. Indeed, apache receive the file perfectly and I could see the file data, and other request params.

使用Rails不会发生相同的情况,在阅读了HTTP 1.1多部分主题的文档之后,我意识到问题与发布文件格式有关.

With Rails the same doesn't occur, and after reading the documentation of HTTP 1.1 multipart topic, I realize that the problem was related to the post file format.

构建此类文件时,需要详细构建它,这意味着在正确的位置包含\ r和\ n之类的所有特殊字符.

When you built this kind of file, you need to build it in details, and this means include all the special characters like \r and \n in the right place.

因此正确的发布文件应如下所示(\ r \ n用于说明,但应该在其中吗?)

So the correct post file looks like this (the \r\n is for illustration, but should be there, you know?):

--boundary_hash\r\n
Content-Disposition: form-data; name="your_form_field";\r\n
Content-Type: text/plain\r\n
\r\n
your form field data\r\n
--boundary_hash\r\n
Content-Disposition: form-data; name="another_field";\r\n
Content-Type: text/plain\r\n
\r\n
another field data\r\n
--boundary_hash\r\n
Content-Disposition: form-data; name="filename"; filename="cf_login.png"\r\n
Content-Type: image/png\r\n
\r\n
base64 file content\r\n
--boundary_hash--\r\n

当您打开此文件时,您实际上会看到以下内容:

When you open this file you see this actually:

--boundary_hash
Content-Disposition: form-data; name="your_form_field";
Content-Type: text/plain

your form field data
--boundary_hash
Content-Disposition: form-data; name="another_field";
Content-Type: text/plain

another field data
--boundary_hash
Content-Disposition: form-data; name="filename"; filename="cf_login.png"
Content-Type: image/png

base64 file content
--boundary_hash--

希望对您有所帮助.

干杯.

这篇关于Apache基准测试Multipart/Form-Data的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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