如何通过HTTP发送MIME? [英] How to send MIME over HTTP?

查看:127
本文介绍了如何通过HTTP发送MIME?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过HTTP POST请求(MIME编码)以.zip存档的形式将某些数据发送到服务器.我认为这仅意味着我需要在请求标头中指定MIME类型.但是我对应该放入请求的正文感到困惑.到目前为止,我可以看到两种方法:

I need to send certain data to the server in a .zip archive, over HTTP POST request, MIME encoded. I take it that means only that I need to specify MIME type in a request header. But I'm confused as to what should I put in request's body. So far I can see two ways to do it:

  1. 通常,就我而言(对不起,我不是网络程序员,所以对HTTP有点la脚),POST请求正文由对parameter_name = some + data除以'&'组成.我是否应该以相同的方式进行操作,并在其中一个参数中将我的文件内容写入base64中?那也可以让我提供补充参数.

  1. Usually, as I take it (sorry, I'm not a web coder, so kinda lame with HTTP), POST request body consists of pairs parameter_name=some+data divided by '&'. Should I do it the same way and write contents of my file in base64 in one of parameters? That would also let me provide supplemental parameters.

还是应该只用文件内容填充POST正文(在base64中,对吗?)?如果是这样,有没有办法提供有关该文件的其他信息?

Or should I just fill POST body with contents of my file (in base64, right?)? If so, is there any way to provide additional info about the file?

这些方法中只有一种是可以接受的,还是两者都可以?如果是这样,什么是最佳做法?

Is only one of theese ways acceptable or are both? If so, what would be the best practice?

此外,将非常感谢Qt的C ++代码示例,但完全没有必要:)

Also, code sample in C++ for Qt would be very-very much appreciated, but totally not necessary :)

推荐答案

POST请求中的整个key = value主体仅用于将表单数据发送到服务器时.如果只想发布.zip文件的内容,则可以将其作为POST正文发送,而无需像您所描述的那样将其设置为表单发布.您可以在请求中设置以下标头:

The whole key=value body in POST requests is just for when you are sending form-data to your server. If you want to POST only the contents of a .zip file you can just send that as the body of your POST, no need to set it up like a form post as you describe. You can set the following headers in the request:

Content-Type: application/zip
Content-Disposition: attachment; filename=myzip.zip

您甚至不必对主体进行base64编码,尽管如果这正是您的服务器所期望的那样.

You don't even necessarily have to base64 encode the body, although you should if that's what your server is expecting.

Content-Disposition是您需要描述有关文件上传的更多内容的东西.您可以在此处找到有关它的一些详细信息:

The Content-Disposition is the thing you need to describe more about your file upload. You can find some details about it here:

http://en.wikipedia.org/wiki/MIME#Content-Disposition

在这里

http://www.ietf.org/rfc/rfc2183.txt

在服务器端,您只需要编写一些代码即可使响应主体保持完整(这很简单,尽管YMMV取决于语言和框架),并根据需要进行处理.

At the server end, you just need to write some code which will get the response body in its entirity (which is straightforward, although YMMV depending on language and framework), and handle it however you want.

对于一个真实的例子,您可能会发现查看AtomPub的操作方式很有帮助:

For a real world example, you might find it useful to look at, say, AtomPub for how this is done:

http://bitworking.org/projects/atom/rfc5023.html

这篇关于如何通过HTTP发送MIME?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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