<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Follow Redirects——模具行业从业者必备知识手册]]></title><description><![CDATA[<p dir="auto">&lt;h3&gt;Follow Redirects&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;Drop-in replacement for Node's &lt;code&gt;http&lt;/code&gt; and &lt;code&gt;https&lt;/code&gt; modules that automatically follows redirects.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;&lt;a href="upload://u6mWk1mXA1u3u5hkb4wBWmtW220.svg"&gt;&lt;img src="<a href="https://www.npmjs.com/package/follow-redirects" rel="nofollow ugc">https://www.npmjs.com/package/follow-redirects</a>" alt="npm version&lt;/a&gt;"&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="upload://miOrWterVShmDN2zS0noAMRNVMK.svg"&gt;&lt;img src="<a href="https://github.com/follow-redirects/follow-redirects/actions" rel="nofollow ugc">https://github.com/follow-redirects/follow-redirects/actions</a>" alt="Build Status&lt;/a&gt;"&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="upload://2jMWsjNzhhwh1y6tmIrND4jaFIb.svg"&gt;&lt;img src="<a href="https://coveralls.io/r/follow-redirects/follow-redirects?branch=master" rel="nofollow ugc">https://coveralls.io/r/follow-redirects/follow-redirects?branch=master</a>" alt="Coverage Status&lt;/a&gt;"&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="upload://ollu8Sa2Rqd3epnC3OfdVUnfDiX.svg"&gt;&lt;img src="<a href="https://www.npmjs.com/package/follow-redirects" rel="nofollow ugc">https://www.npmjs.com/package/follow-redirects</a>" alt="npm downloads&lt;/a&gt;"&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="upload://xcstV1vVc603T7KBtv0K3dzfC3v.svg"&gt;&lt;img src="<a href="https://github.com/sponsors/RubenVerborgh" rel="nofollow ugc">https://github.com/sponsors/RubenVerborgh</a>" alt="Sponsor on GitHub&lt;/a&gt;"&gt;&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;&lt;code&gt;follow-redirects&lt;/code&gt; provides &lt;a href="<a href="https://nodejs.org/api/http.html#http_http_request_options_callback" rel="nofollow ugc">https://nodejs.org/api/http.html#http_http_request_options_callback</a>"&gt;request&lt;/a&gt; and &lt;a href="<a href="https://nodejs.org/api/http.html#http_http_get_options_callback" rel="nofollow ugc">https://nodejs.org/api/http.html#http_http_get_options_callback</a>"&gt;get&lt;/a&gt;&lt;/p&gt;<br />
&lt;p&gt; methods that behave identically to those found on the native &lt;a href="<a href="https://nodejs.org/api/http.html#http_http_request_options_callback" rel="nofollow ugc">https://nodejs.org/api/http.html#http_http_request_options_callback</a>"&gt;http&lt;/a&gt; and &lt;a href="<a href="https://nodejs.org/api/https.html#https_https_request_options_callback" rel="nofollow ugc">https://nodejs.org/api/https.html#https_https_request_options_callback</a>"&gt;https&lt;/a&gt;&lt;/p&gt;<br />
&lt;p&gt; modules, with the exception that they will seamlessly follow redirects.&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
const { http, https } = require('follow-redirects');</p>
<p dir="auto">http.get('<a href="http://bit.ly/900913" rel="nofollow ugc">http://bit.ly/900913</a>', response =&gt; {<br />
response.on('data', chunk =&gt; {<br />
console.log(chunk);<br />
});<br />
}).on('error', err =&gt; {<br />
console.error(err);<br />
});<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;p&gt;You can inspect the final redirected URL through the &lt;code&gt;responseUrl&lt;/code&gt; property on the &lt;code&gt;response&lt;/code&gt;.&lt;/p&gt;<br />
&lt;p&gt;If no redirection happened, &lt;code&gt;responseUrl&lt;/code&gt; is the original request URL.&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
const request = https.request({<br />
host: '<a href="http://bitly.com" rel="nofollow ugc">bitly.com</a>',<br />
path: '/UHfDGO',<br />
}, response =&gt; {<br />
console.log(response.responseUrl);<br />
// '<a href="http://duckduckgo.com/robots.txt" rel="nofollow ugc">http://duckduckgo.com/robots.txt</a>'<br />
});<br />
request.end();<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;h3&gt;Options&lt;/h3&gt;<br />
&lt;h4&gt;Global options&lt;/h4&gt;<br />
&lt;p&gt;Global options are set directly on the &lt;code&gt;follow-redirects&lt;/code&gt; module:&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
const followRedirects = require('follow-redirects');<br />
followRedirects.maxRedirects = 10;<br />
followRedirects.maxBodyLength = 20 * 1024 * 1024; // 20 MB<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;p&gt;The following global options are supported:&lt;/p&gt;</p>
<p dir="auto">&lt;ul&gt;<br />
&lt;li&gt;&lt;code&gt;maxRedirects&lt;/code&gt; (default: &lt;code&gt;21&lt;/code&gt;) – sets the maximum number of allowed redirects; if exceeded, an error will be emitted.&lt;/li&gt;<br />
&lt;/ul&gt;</p>
<p dir="auto">&lt;ul&gt;<br />
&lt;li&gt;&lt;code&gt;maxBodyLength&lt;/code&gt; (default: 10MB) – sets the maximum size of the request body; if exceeded, an error will be emitted.&lt;/li&gt;<br />
&lt;/ul&gt;</p>
<p dir="auto">&lt;h4&gt;Per-request options&lt;/h4&gt;<br />
&lt;p&gt;Per-request options are set by passing an &lt;code&gt;options&lt;/code&gt; object:&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
const url = require('url');<br />
const { http, https } = require('follow-redirects');</p>
<p dir="auto">const options = url.parse('<a href="http://bit.ly/900913" rel="nofollow ugc">http://bit.ly/900913</a>');<br />
options.maxRedirects = 10;<br />
options.beforeRedirect = (options, response, request) =&gt; {<br />
// Use this to adjust the request options upon redirecting,<br />
// to inspect the latest response headers,<br />
// or to cancel the request by throwing an error</p>
<p dir="auto">// response.headers = the redirect response headers<br />
// response.statusCode = the redirect response code (eg. 301, 307, etc.)</p>
<p dir="auto">// request.url = the requested URL that resulted in a redirect<br />
// request.headers = the headers in the request that resulted in a redirect<br />
// request.method = the method of the request that resulted in a redirect<br />
if (options.hostname === "<a href="http://example.com" rel="nofollow ugc">example.com</a>") {<br />
options.auth = "user:password";<br />
}<br />
};<br />
http.request(options);<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;p&gt;In addition to the &lt;a href="<a href="https://nodejs.org/api/http.html#http_http_request_options_callback" rel="nofollow ugc">https://nodejs.org/api/http.html#http_http_request_options_callback</a>"&gt;standard HTTP&lt;/a&gt; and &lt;a href="<a href="https://nodejs.org/api/https.html#https_https_request_options_callback" rel="nofollow ugc">https://nodejs.org/api/https.html#https_https_request_options_callback</a>"&gt;HTTPS options&lt;/a&gt;,&lt;/p&gt;<br />
&lt;p&gt;the following per-request option&lt;/p&gt;</p>
<p dir="auto">&lt;hr&gt;<br />
&lt;p&gt;这个参数你们一般设多少？评论区说说。&lt;/p&gt;</p>
]]></description><link>https://forum.mj7.cn/topic/7204/follow-redirects-模具行业从业者必备知识手册</link><generator>RSS for Node</generator><lastBuildDate>Fri, 02 Oct 2026 09:34:14 GMT</lastBuildDate><atom:link href="https://forum.mj7.cn/topic/7204.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Apr 2026 21:55:57 GMT</pubDate><ttl>60</ttl></channel></rss>