http context type
- User
User: http context type Assistant: HTTP context types, often referred to as "Content Types," are indicators that tell the client (usually a web browser) what kind of data is being sent from the server. They are specified in the
Content-Typeheader of an HTTP request or response.Here are some common HTTP context types:
-
Text Formats:
text/plain: Plain text.text/html: HTML document.text/css: Cascading Style Sheets.text/javascript: JavaScript code (now oftenapplication/javascript).
-
Image Formats:
image/jpeg: JPEG image.image/png: PNG image.image/gif: GIF image.image/svg+xml: SVG image.
-
Audio and Video Formats:
audio/mpeg: MP3 audio.audio/wav: WAV audio.video/mp4: MP4 video.video/x-msvideo: AVI video.
-
Application Formats:
application/json: JSON format.application/xml: XML format.application/pdf: PDF document.application/octet-stream: Binary data (used for arbitrary binary data).
-
Multipart Formats:
multipart/form-data: Used for forms that include file uploads.multipart/byteranges: Used for handling byte-range requests.
Example of Setting Content-Type in HTTP Response
Here's how you might set the
Content-Typeheader in a simple HTTP response using different programming languages:Example in Node.js (Express)
app.get('/example', (req, res) => { res.set('Content-Type', 'application/json'); res.send({ message: 'Hello, World!' }); });Example in Python (Flask)
from flask import Flask, jsonify app = Flask(__name__) @app.route('/example') def example(): return jsonify(message='Hello, World!'), 200, {'Content-Type': 'application/json'} -
- Assistant
当然可以!以下是关于 HTTP 内容类型的详细信息的中文翻译:
HTTP 内容类型
HTTP 内容类型通常称为“内容类型”,是指示客户端(通常是网页浏览器)服务器所发送数据类型的标识。它们在 HTTP 请求或响应的
Content-Type头部中指定。以下是一些常见的 HTTP 内容类型:
-
文本格式:
text/plain:纯文本。text/html:HTML 文档。text/css:层叠样式表。text/javascript:JavaScript 代码(现在通常使用application/javascript)。
-
图像格式:
image/jpeg:JPEG 图像。image/png:PNG 图像。image/gif:GIF 图像。image/svg+xml:SVG 图像。
-