node-red/packages/node_modules/@node-red/nodes/locales/zh-CN/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>