Questions tagged [content-type]

The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET.

The Content-Type entity-header field indicates the media type (or MIME type) of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET.

Content-Type   = "Content-Type" ":" media-type

An example of the field for HTML documents is:

Content-Type: text/html; charset=ISO-8859-4

For a PNG file, it would be:

Content-Type: image/png

Source: http://www.w3.org/

HTTP Specification : Section 14 : Header Field Definitions

Wikipedia articles:

  1. MIME
  2. Internet media type
2233 questions
67
votes
4 answers

Return jpeg image from Asp.Net Core WebAPI

Using asp.net core web api, I want to have my controller action method to return an jpeg image stream. In my current implementation, browser displays only a json string. My expectation is to see the image in the browser. While debugging using…
hannes neukermans
  • 8,470
  • 5
  • 30
  • 44
67
votes
3 answers

Force nginx to send specific Content-Type

How to overwrite default Content-Type in nginx? Currently when I request 01.dae file, there's Content-Type: application/octet-stream; And I want it to be Content-Type: application/xml; I tried something like location ~* \.dae$ { …
Kasheftin
  • 2,942
  • 4
  • 28
  • 46
63
votes
13 answers

New lines (\r\n) are not working in email body

I am using PHP mail() function: $to = 'AAAA '; $subject = 'BBBB'; $message = "CCCC\r\nCCCC CCCC \r CCC \n CCC \r\n CCC \n\r CCCC"; $headers = 'From: DDD' . "\r\n"; $headers .=…
Verbatus
  • 733
  • 1
  • 5
  • 10
55
votes
3 answers

HTTP Headers for File Downloads

I've written a PHP script that handles file downloads, determining which file is being requested and setting the proper HTTP headers to trigger the browser to actually download the file (rather than displaying it in the browser). I now have a…
Wilco
  • 31,070
  • 47
  • 124
  • 158
54
votes
7 answers

File extensions and MIME Types in .NET

I want to get a MIME Content-Type from a given extension (preferably without accessing the physical file). I have seen some questions about this and the methods described to perform this can be resumed in: Use registry information. Use urlmon.dll's…
Marc Climent
  • 9,006
  • 2
  • 47
  • 54
53
votes
1 answer

What is the exact difference between content-type: text/json and application/json?

What is the exact difference between Content-type: text/json Content-type: application/json I've been using them randomly and never find any output difference in both http headers?
Girish
  • 11,254
  • 3
  • 32
  • 48
51
votes
2 answers

Is there an enum for the ContentType property on a HttpWebResponse ("text/plain", "application/octet-stream" etc.)?

The closest thing I could find was System.Net.Mime.MediaTypeNames but that doesn't seem to have everything (like json) since it seems to be more focused around email attachments.
will
  • 3,741
  • 5
  • 31
  • 47
50
votes
6 answers

Determine file type of an image

I'm downloading some images from a service that doesn't always include a content-type and doesn't provide an extension for the file I'm downloading (ugh, don't ask). What's the best way to determine the image format in .NET? The application that is…
Eric
  • 908
  • 1
  • 7
  • 13
49
votes
7 answers

Check file uploaded is in csv format

I am uploading a file in php and only want to upload it if it's a csv file. I believe my syntax is right for the content type. It always goes to else statement when it's a csv file. What I am doing wrong here? if (($_FILES["file"]["type"] ==…
theking963
  • 2,035
  • 6
  • 25
  • 40
49
votes
2 answers

How can I obtain the model's name or the content type of a Django object?

Let's say I am in the save code. How can I obtain the model's name or the content type of the object, and use it? from django.db import models class Foo(models.Model): ... def save(self): I am here....I want to obtain the model_name…
Seitaridis
  • 4,301
  • 9
  • 51
  • 83
49
votes
2 answers

How can I remove default headers that cURL sends?

Curl by default adds headers such as Content-type and User-agent. Normally that is a good thing but I'm trying to test what our server does when those headers are missing. My problem is with the Content-type header. If it is missing, the server…
Jilles van Gurp
  • 6,938
  • 4
  • 34
  • 41
49
votes
13 answers

How do I find the mime-type of a file with php?

Ok, so I have an index.php file which has to process many different file types. how do I guess the filetype based on the REQUEST_URI. If I request http://site/image.jpg, and all requests redirect through index.php, which looks like this
Issac Kelly
  • 5,999
  • 6
  • 40
  • 50
48
votes
7 answers

how to post plain text to ASP.NET Web API endpoint?

I have an ASP.NET Web API endpoint with controller action defined as follows : [HttpPost] public HttpResponseMessage Post([FromBody] object text) If my post request body contains plain text ( i.e. should not be interpreted as json, xml, or any…
BaltoStar
  • 6,511
  • 13
  • 46
  • 67
47
votes
2 answers

Set default content_type for Sinatra

In Sinatra is it possible to make content_type 'application/json' the default? Because I'm building a REST API.
ma11hew28
  • 106,283
  • 107
  • 420
  • 616
45
votes
2 answers

Are HTTP headers (Content-Type, &c.) case-sensitive?

Perhaps I'm skimming too fast, but couldn't find this specifically documented. In my particular case, I'm wondering about the "Content-Type" header, but I'm assuming the same rules would apply to other standard headers. Are these case sensitive,…
anonymous coward
  • 11,594
  • 10
  • 51
  • 89