简体   繁体   English

HTTP POST 请求中的自定义内容类型?

[英]Custom Content-Type in HTTP POST request?

I have a custom data format that I'm sending in an HTTP post body.我有一个自定义数据格式,我在 HTTP 帖子正文中发送。 I'm wondering if I should use text/plain or application/octet-stream , or if I could use a custom Content-Type ?我想知道我是否应该使用text/plainapplication/octet-stream ,或者我是否可以使用自定义Content-Type Is making it custom in bad taste?定制它的品味很差吗?

The format looks like this:格式如下所示:

test0,id=28084 type=high,18765003 138456387

It's a good idea to use a custom mime type.使用自定义 mime 类型是个好主意。

If the name of your product is 'sally', you might for example use:如果您的产品名称是“sally”,您可以例如使用:

application/prs.sally.testresults
application/vnd.sally.testresults
text/prs.sally.testresults
text/vnd.sally.testresults
application/x.sally.testresults
application/x.sally.testresults
text/x.sally.testresults
text/x.sally.testresults

The prs stands for 'personal', vnd stands for 'vendor', and x stands for unregistered. prs代表“个人”, vnd代表“供应商”, x代表未注册。

You're officially required to register your prs or vnd mimetypes, but frankly very few do and it doesn't matter that much as long as you make an effort to make it reasonably unique.你需要正式注册你的prsvnd MIME类型,但坦率地说很少做,它并不重要只要尽你作出努力,使之合理独一无二的。

The difference between application and text can be pretty subtle, because things like JSON and Javascript also use application . applicationtext之间的区别可能非常微妙,因为 JSON 和 Javascript 之类的东西也使用application

Generally using application means intermediates like proxies will never try to automatically change things like character encoding, whereas text they might.通常使用application意味着像代理这样的中间体永远不会尝试自动更改字符编码等内容,而它们可能会更改text

If something is more like a computer-interpreted format I would probably prefer application , and if it's more intended as human-readable text, then text is probably the right move.如果某些东西更像是计算机解释的格式,我可能更喜欢application ,如果它更像是人类可读的文本,那么text可能是正确的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM