node-red/packages/node_modules/@node-red/nodes/locales/zh-TW/network/21-httprequest.html

79 lines
5.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!--
Copyright JS Foundation and other contributors, http://js.foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-help-name="http request">
<p>發送HTTP請求並返回響應</p>
<h3>輸入</h3>
<dl class="message-properties">
<dt class="optional">url <span class="property-type">字符串</span></dt>
<dd>如果未在節點中配置則此可選屬性設置請求的url</dd>
<dt class="optional">method <span class="property-type">字符串</span></dt>
<dd>如果未在節點中配置則此可選屬性設置請求的HTTP方法必須是<code>GET</code>,<code>PUT</code>,<code>POST</code>,<code>PATCH</code><code>DELETE</code></dd>
<dt class="optional">headers <span class="property-type">object</span></dt>
<dd>設置請求的HTTP頭</dd>
<dt class="optional">cookies <span class="property-type">object</span></dt>
<dd>如果設置則可用于發送帶有請求的cookie</dd>
<dt class="optional">payload</dt>
<dd>發送爲請求的正文</dd>
<dt class="optional">rejectUnauthorized</dt>
<dd>如果設置爲<code>false</code>使https</dd>
<dt class="optional">followRedirects</dt>
<dd>如果設置爲<code>false</code>HTTP 301<code>true</code></dd>
<dt class="optional">requestTimeout</dt>
<dd>如果設置爲正數毫秒將覆蓋全局設置的<code>httpRequestTimeout</code></dd>
</dl>
<h3>輸出</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">字符串 | object | buffer</span></dt>
<dd>響應的正文可以將節點配置爲以字符串形式返回主體嘗試將其解析爲JSON字符串或將其保留爲二進制buffer</dd>
<dt>statusCode <span class="property-type">數值</span></dt>
<dd>響應的狀態碼如果請求無法完成則返回錯誤碼</dd>
<dt>headers <span class="property-type">object</span></dt>
<dd>包含響應頭的對象</dd>
<dt>responseUrl <span class="property-type">字符串</span></dt>
<dd>如果在處理請求時發生任何重定向則此屬性爲最終重定向的URL否則則爲原始請求的URL</dd>
<dt>responseCookies <span class="property-type">object</span></dt>
<dd>如果響應包含cookie則此屬性是每個cookie的名稱/鍵值對的對象</dd>
<dt>redirectList <span class="property-type">數組</span></dt>
<dd>如果請求被重定向了一次或多次則累積的信息將被添加到此屬性location是下一個重定向目標cookie是從重定向源返回的cookie</dd>
</dl>
<h3>詳細</h3>
<p>在節點內配置後URL屬性可以包含<a href="http://mustache.github.io/mustache.5.html" target="_blank">mustache樣式</a>標簽。 這些標簽允許使用傳入消息的值來構造url。例如如果url設置爲<code>example.com/{{{{topic}}}</code><code>msg.topic</code>使{{{...}}}mustache/ &</p>
<p>節點可以選擇自動將<code>msg.payload</code>GET<code>msg.payload</code></p>
<p><b>注意</b>使<code>http_proxy=...</code>Node-RED使</p>
<h4>使用多個HTTP請求節點</h4>
<p>爲了在一個流程中多次使用該節點必須要注意<code>msg.headers</code>使<code>msg.headers</code><code>msg.headers</code><code>{}</code></p>
<h4>Cookie處理</h4>
<p>傳遞給節點的<code>cookies</code>/cookie<code>value</code></p>
<p>請求返回的所有cookie都將在<code>responseCookies</code></p>
<h4>內容類型處理</h4>
<p>如果<code>msg.payload</code><code>application/json</code></p>
<p>要將請求編碼爲表單數據應將<code>msg.headers[content-type]</code><code>application/x-www-form-urlencoded</code></p>
<h4>文件上傳</h4>
<p>要執行文件上傳應將<code>msg.headers["content-type"]</code><code>multipart/form-data</code><code>msg.payload</code></p>
<pre><code>{
"KEY": {
"value": FILE_CONTENTS,
"options": {
"filename": "FILENAME"
}
}
}</code></pre>
<p><code>KEY</code>,<code>FILE_CONTENTS</code><code>FILENAME</code></p>
</script>