StringContent-mediaType参数 [英] StringContent - mediaType Parameter

查看:430
本文介绍了StringContent-mediaType参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道'mediaType'参数对StringContent的构造函数有什么作用?在其MSDN页面上没有列出任何内容.

Does anyone have any idea what the 'mediaType' parameter does for the StringContent's constructor? Nothing is listed on its MSDN page.

谢谢.

推荐答案

哇,是创建StringContent的新实例时,它总是设置媒体类型.如果您未指定,则使用"text/plain";否则,它将使用您传入的任何内容.(似乎对传入的值进行了一些验证,但我不太了解它的作用.)

When you create a new instance of StringContent, it always sets a media type. If you don't specify one, it uses "text/plain"; otherwise, it uses whatever you passed in. (There appears to be some validation done on the value you pass in, but I don't really understand what it's doing.)

该媒体类型值随后用于实例化一个新的MediaTypeHeaderValue,该新MediaTypeHeaderValue分配给您的StringContent的Headers.ContentType属性.

That media type value is then used to instantiate a new MediaTypeHeaderValue, which is assigned to your StringContent's Headers.ContentType property.

文档中查找标头:

获取RFC 2616中定义的HTTP内容标头.

Gets the HTTP content headers as defined in RFC 2616.

对Content-Type属性的评论:

The comment on the Content-Type property:

HTTP响应中Content-Type内容标头的值.

The value of the Content-Type content header on an HTTP response.

所有这些,显然是在指定HTTP内容类型.

So all that to say, it's apparently specifying the HTTP content type.

这是类型的完整列表,太长,无法包含在此处.我确定MSDN上也有一个列表,但找不到.

Here's a full list of types, which is too long to include here. I'm sure there's a list somewhere on MSDN too but I couldn't find one.

这篇关于StringContent-mediaType参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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