<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>http://test.largeq.cn/index.php?action=history&amp;feed=atom&amp;title=Nodejs%2Fhttp%2FServerResponse%2FsetHeader</id>
	<title>Nodejs/http/ServerResponse/setHeader - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="http://test.largeq.cn/index.php?action=history&amp;feed=atom&amp;title=Nodejs%2Fhttp%2FServerResponse%2FsetHeader"/>
	<link rel="alternate" type="text/html" href="http://test.largeq.cn/index.php?title=Nodejs/http/ServerResponse/setHeader&amp;action=history"/>
	<updated>2026-04-20T15:30:50Z</updated>
	<subtitle>本wiki的该页面的版本历史</subtitle>
	<generator>MediaWiki 11.45.14</generator>
	<entry>
		<id>http://test.largeq.cn/index.php?title=Nodejs/http/ServerResponse/setHeader&amp;diff=217&amp;oldid=prev</id>
		<title>IVEN：/* 参数 */</title>
		<link rel="alternate" type="text/html" href="http://test.largeq.cn/index.php?title=Nodejs/http/ServerResponse/setHeader&amp;diff=217&amp;oldid=prev"/>
		<updated>2019-05-27T21:43:45Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;参数&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2019年5月27日 (一) 21:43的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l11&quot; &gt;第11行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第11行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==参数==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==参数==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;name &amp;lt;string&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/ins&gt;name &amp;lt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;[[&lt;/ins&gt;string&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;]]&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;value &amp;lt;any&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/ins&gt;value &amp;lt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;[[数据类型|&lt;/ins&gt;any&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;]]&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==返回==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==返回==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;void&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;void&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>IVEN</name></author>
		
	</entry>
	<entry>
		<id>http://test.largeq.cn/index.php?title=Nodejs/http/ServerResponse/setHeader&amp;diff=213&amp;oldid=prev</id>
		<title>IVEN：创建页面，内容为“设置响应头 response.setHeader(name, value) ==版本历史== {| class=&quot;wikitable&quot; |v10.15.3 |被小青青复制到笔记中 |- |v0.4.0  |新增于: v0.4.0  |}  =…”</title>
		<link rel="alternate" type="text/html" href="http://test.largeq.cn/index.php?title=Nodejs/http/ServerResponse/setHeader&amp;diff=213&amp;oldid=prev"/>
		<updated>2019-05-27T10:56:24Z</updated>

		<summary type="html">&lt;p&gt;创建页面，内容为“设置响应头 response.setHeader(name, value) ==版本历史== {| class=&amp;quot;wikitable&amp;quot; |v10.15.3 |被小青青复制到笔记中 |- |v0.4.0  |新增于: v0.4.0  |}  =…”&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;设置响应头&lt;br /&gt;
response.setHeader(name, value)&lt;br /&gt;
==版本历史==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|v10.15.3&lt;br /&gt;
|被小青青复制到笔记中&lt;br /&gt;
|-&lt;br /&gt;
|v0.4.0 &lt;br /&gt;
|新增于: v0.4.0 &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==参数==&lt;br /&gt;
name &amp;lt;string&amp;gt;&lt;br /&gt;
value &amp;lt;any&amp;gt;&lt;br /&gt;
==返回==&lt;br /&gt;
void&lt;br /&gt;
==备注==&lt;br /&gt;
为隐式响应头设置单个响应头的值。 如果此响应头已存在于待发送的响应头中，则其值将被替换。 在这里可以使用字符串数组来发送具有相同名称的多个响应头。 非字符串值将被原样保存。 因此 response.getHeader() 可能返回非字符串值。 但是非字符串值将转换为字符串以进行网络传输。&lt;br /&gt;
&lt;br /&gt;
response.setHeader('Content-Type', 'text/html');&lt;br /&gt;
或：&lt;br /&gt;
&lt;br /&gt;
response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);&lt;br /&gt;
尝试设置包含无效字符的响应头字段名称或值将导致抛出 TypeError。&lt;br /&gt;
&lt;br /&gt;
当使用 response.setHeader() 设置响应头时，它们将与传给 response.writeHead() 的任何响应头合并，其中 response.writeHead() 的响应头优先。&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;JavaScript&amp;quot;&amp;gt;&lt;br /&gt;
// 返回 content-type = text/plain&lt;br /&gt;
const server = http.createServer((req, res) =&amp;gt; {&lt;br /&gt;
  res.setHeader('Content-Type', 'text/html');&lt;br /&gt;
  res.setHeader('X-Foo', 'bar');&lt;br /&gt;
  res.writeHead(200, { 'Content-Type': 'text/plain' });&lt;br /&gt;
  res.end('ok');&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
如果调用了 response.writeHead() 方法并且尚未调用此方法，则它将直接将提供的响应头值写入网络通道而不在内部进行缓存，并且响应头上的 response.getHeader() 将不会产生预期的结果。 如果需要渐进的响应头填充以及将来可能的检索和修改，则使用 response.setHeader() 而不是 response.writeHead()。&lt;/div&gt;</summary>
		<author><name>IVEN</name></author>
		
	</entry>
</feed>