Is there any disadvantage of using: text/plain; charset=”UTF-8″
Nope, all it’s there for is to tell the browser which character set to decode your response with.
Nope, all it’s there for is to tell the browser which character set to decode your response with.
For Node applications, there is a more up-to-date answer now, which is to use the mime-types NPM package, e.g.: var mime = require(‘mime-types’), fileExtension = mime.extension(‘text/plain’);
You can use magic numbers to detect a MIME type (check here the list of file signatures). However, file signatures are not 100% reliable and you can easily encounter false positives. Of course, there are tasks when a such solution is more than enough. So if you have a Base64 string and want to identify … Read more
In .Net 4.5 you can use MimeMapping.GetMimeMapping: string contentType = MimeMapping.GetMimeMapping(“someFileName.pdf”) // contentType = “application/pdf” More information
The content type is a header of the content, not of the request, which is why this is failing. AddWithoutValidation as suggested by Robert Levy may work, but you can also set the content type when creating the request content itself (note that the code snippet adds application/json in two places-for Accept and Content-Type headers): … Read more
First thing to understand is that the RequestMapping#produces() element in @RequestMapping(value = “/json”, method = RequestMethod.GET, produces = “application/json”) serves only to restrict the mapping for your request handlers. It does nothing else. Then, given that your method has a return type of String and is annotated with @ResponseBody, the return value will be handled … Read more
Unfortunately FormHttpMessageConverter (which is used for @RequestBody-annotated parameters when content type is application/x-www-form-urlencoded) cannot bind target classes (as @ModelAttribute can). Therefore you need @ModelAttribute instead of @RequestBody. If you don’t need to pass different content types to that method you can simply replace the annotation: @RequestMapping(method = RequestMethod.POST) public ModelAndView create(@ModelAttribute UserAccountBean account) { … … Read more
[2019] .NET Core / Standard compatible portable way While Bradley’s answer continues to be perfect on regular old Windows machines running .NET Framework, Registry is Windows-specific and will fail when porting the app to a non-Windows environment. Fortunately there is a very small NuGet library that essentially contains a hardcoded map of the official MIME … Read more
In regards to XML/HTML document fragments, other than the xml-fragment referenced in the comments (now labeled as “no longer maintained”), there don’t appear to be any explicit, official references to document fragments and the content type header. However, some points to consider: The xml-fragment spec treats full documents and fragments the same in regards to … Read more