“application/json” constant in .NET framework

后端 未结 2 1131
栀梦
栀梦 2021-02-04 22:44

I\'ve just declared a constant for the \"application/json\" content type in one of my classes.

public const string JsonContentType = \"application/json\";
         


        
2条回答
  •  臣服心动
    2021-02-04 23:37

    While there are some MIME constants defined in MediaTypeNames (see here), there no constant for "application/json".

    Putting additional content types in a shared const is probably best practice, better than defining them in string literals a million times throughout your code at least.

    Plus it gives you the flexibility of using new/custom MIME types, which a specific .NET version might not have.

提交回复
热议问题