6.2.0 - 重新设计及编写项目文档; 新增多语言适配; 丰富控件选择器功能; 优化夜间模式适配等

This commit is contained in:
SuperMonster003
2023-01-21 22:17:16 +08:00
parent 069932c8d3
commit 10960ddbee
2139 changed files with 66316 additions and 41795 deletions

View File

@@ -1,80 +1,134 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTTP | Auto.js 4.1.0 文档</title>
<link rel="stylesheet" href="assets/fonts.css">
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/sh.css">
<link rel="canonical" href="https://nodejs.org/api/http.html">
<meta charset="utf-8">
<title>HTTP | AutoJs6 文档 - 6.2.0</title>
<link rel="stylesheet" href="assets/fonts.css">
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/sh.css">
<link rel="canonical" href="https://nodejs.org/api/http.html">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="viewport" content="user-scalable=no">
</head>
<body class="alt apidoc" id="api-section-http">
<div id="content" class="clearfix">
<div id="content" class="clearfix">
<div id="column2" class="interior">
<div id="intro" class="interior">
<a href="/" title="返回首页">
Auto.js
</a>
</div>
<ul>
<li><a class="nav-documentation" href="documentation.html">关于本文档</a></li>
<li><a class="nav-http active-www-w3school-com-cn-js-pro_js_syntax-asp" href="http://www.w3school.com.cn/js/pro_js_syntax.asp">W3CSchool - ECMAScript教程</a></li>
<li><a class="nav-http-es6-ruanyifeng-com-README" href="http://es6.ruanyifeng.com/#README">阮一峰 - ECMAScript 6教程</a></li>
</ul>
<div class="line"></div>
<ul>
<div id="intro" class="interior">
<a href="/" title="返回首页">
AutoJs6
</a>
</div>
<ul>
<li><a class="nav-overview" href="overview.html">Overview - 综述</a></li>
<li><a class="nav-qa" href="qa.html">Q&amp;A - 常见问题</a></li>
<li><a class="nav-app" href="app.html">App - 应用</a></li>
<li><a class="nav-console" href="console.html">Console - 控制台</a></li>
<li><a class="nav-coordinates-based-automation" href="coordinates-based-automation.html">CoordinatesBasedAutomation - 基于坐标的操作</a></li>
<li><a class="nav-device" href="device.html">Device - 设备</a></li>
<li><a class="nav-dialogs" href="dialogs.html">Dialogs - 对话框</a></li>
<li><a class="nav-engines" href="engines.html">Engines - 脚本引擎</a></li>
<li><a class="nav-events" href="events.html">Events - 事件与监听</a></li>
<li><a class="nav-floaty" href="floaty.html">Floaty - 悬浮窗</a></li>
<li><a class="nav-files" href="files.html">Files - 文件系统</a></li>
<li><a class="nav-globals" href="globals.html">Globals - 一般全局函数</a></li>
<li><a class="nav-http" href="http.html">Http - HTTP</a></li>
<li><a class="nav-images" href="images.html">Images - 图片与图色处理</a></li>
<li><a class="nav-keys" href="keys.html">Keys - 按键模拟</a></li>
<li><a class="nav-media" href="media.html">Media - 多媒体</a></li>
<li><a class="nav-modules" href="modules.html">Modules - 模块</a></li>
<li><a class="nav-widgets-based-automation" href="widgets-based-automation.html">WidgetsBasedAutomation - 基于控件的操作</a></li>
<li><a class="nav-sensors" href="sensors.html">Sensors - 传感器</a></li>
<li><a class="nav-shell" href="shell.html">Shell - Shell命令</a></li>
<li><a class="nav-storages" href="storages.html">Storages - 本地存储</a></li>
<li><a class="nav-threads" href="threads.html">Threads - 多线程</a></li>
<li><a class="nav-timers" href="timers.html">Timers - 定时器</a></li>
<li><a class="nav-ui" href="ui.html">UI - 用户界面</a></li>
<li><a class="nav-https-developer-mozilla-org-zh-CN-docs-Mozilla-Projects-Rhino-Scripting_Java" href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Projects/Rhino/Scripting_Java">Work with Java - 调用Java API</a></li>
<li><a class="nav-documentation" href="documentation.html">About - 关于文档</a></li>
<li><a class="nav-progress" href="progress.html">Progress - 完善进度</a></li>
<li><a class="nav-changelog" href="changelog.html">Changelog - 更新日志</a></li>
<li><a class="nav-qa" href="qa.html">Q&amp;A - 疑难解答</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a class="nav-https-github-com-hyb1996-NoRootScriptDroid" href="https://github.com/hyb1996/NoRootScriptDroid">GitHub项目 &amp; Issue提交</a></li>
<li><a class="nav-http-autojs-org" href="http://autojs.org">Auto.js交流社区</a></li>
<li><a class="nav-http actives-developer-mozilla-org-zh-CN-docs-Web-JavaScript-" href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/">MDN - JavaScript 基础</a></li>
<li><a class="nav-https-zh-javascript-info-" href="https://zh.javascript.info/">JavaScript.info - JavaScript 教程</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a class="nav-global" href="global.html">Global - 全局对象</a></li>
<li><a class="nav-automator" href="automator.html">Automator - 自动化</a></li>
<li><a class="nav-autojs" href="autojs.html">AutoJs6 - 本体应用</a></li>
<li><a class="nav-app" href="app.html">App - 通用应用</a></li>
<li><a class="nav-color" href="color.html">Color - 颜色</a></li>
<li><a class="nav-image" href="image.html">Image - 图像</a></li>
<li><a class="nav-keys" href="keys.html">Keys - 按键</a></li>
<li><a class="nav-device" href="device.html">Device - 设备</a></li>
<li><a class="nav-storages" href="storages.html">Storage - 储存</a></li>
<li><a class="nav-files" href="files.html">File - 文件</a></li>
<li><a class="nav-engines" href="engines.html">Engine - 引擎</a></li>
<li><a class="nav-tasks" href="tasks.html">Task - 任务</a></li>
<li><a class="nav-modules" href="modules.html">Module - 模块</a></li>
<li><a class="nav-plugins" href="plugins.html">Plugins - 插件</a></li>
<li><a class="nav-console" href="console.html">Console - 控制台</a></li>
<li><a class="nav-shell" href="shell.html">Shell</a></li>
<li><a class="nav-media" href="media.html">Media - 多媒体</a></li>
<li><a class="nav-sensors" href="sensors.html">Sensor - 传感器</a></li>
<li><a class="nav-recorder" href="recorder.html">Recorder - 记录器</a></li>
<li><a class="nav-timers" href="timers.html">Timer - 定时器</a></li>
<li><a class="nav-threads" href="threads.html">Thread - 线程</a></li>
<li><a class="nav-continuation" href="continuation.html">Continuation - 协程</a></li>
<li><a class="nav-events" href="events.html">Event - 事件监听</a></li>
<li><a class="nav-dialogs" href="dialogs.html">Dialog - 对话框</a></li>
<li><a class="nav-floaty" href="floaty.html">Floaty - 悬浮窗</a></li>
<li><a class="nav-canvas" href="canvas.html">Canvas - 画布</a></li>
<li><a class="nav-ui" href="ui.html">UI - 用户界面</a></li>
<li><a class="nav-web" href="web.html">Web - 万维网</a></li>
<li><a class="nav-http" href="http.html">HTTP</a></li>
<li><a class="nav-base64" href="base64.html">Base64</a></li>
<li><a class="nav-crypto" href="crypto.html">Crypto - 密文</a></li>
<li><a class="nav-i18n" href="i18n.html">Internationalization - 国际化</a></li>
<li><a class="nav-e4x" href="e4x.html">E4X</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a class="nav-glossaries" href="glossaries.html">Glossaries - 术语</a></li>
<li><a class="nav-exceptions" href="exceptions.html">Exceptions - 异常</a></li>
<li><a class="nav-intentType" href="intentType.html">Intent - 意图</a></li>
<li><a class="nav-runtime" href="runtime.html">Runtime - 运行时</a></li>
<li><a class="nav-context" href="context.html">Context - 上下文</a></li>
<li><a class="nav-activity" href="activity.html">Activity - 活动</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a class="nav-dataTypes" href="dataTypes.html">Data Types - 数据类型</a></li>
<li><a class="nav-uiSelectorType" href="uiSelectorType.html">UiSelector - 选择器</a></li>
<li><a class="nav-uiObjectType" href="uiObjectType.html">UiObject - 控件节点</a></li>
<li><a class="nav-uiObjectCollectionType" href="uiObjectCollectionType.html">UiObjectCollection - 控件集合</a></li>
<li><a class="nav-uiObjectActionsType" href="uiObjectActionsType.html">UiObjectActions - 控件节点行为</a></li>
<li><a class="nav-appType" href="appType.html">App - 应用枚举类</a></li>
<li><a class="nav-versionType" href="versionType.html">Version - 版本工具类</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a class="nav-polyfill" href="polyfill.html">Polyfill - 代码填泥</a></li>
<li><a class="nav-arrayx" href="arrayx.html">Arrayx - Array 扩展</a></li>
<li><a class="nav-numberx" href="numberx.html">Numberx - Number 扩展</a></li>
<li><a class="nav-mathx" href="mathx.html">Mathx - Math 扩展</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a class="nav-scriptingJava" href="scriptingJava.html">Scripting Java - 脚本化 Java</a></li>
<li><a class="nav-apiLevel" href="apiLevel.html">Android API Level - 安卓 API 级别</a></li>
<li><a class="nav-colorTable" href="colorTable.html">Color Table - 颜色列表</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a class="nav-https-github-com-SuperMonster003-AutoJs6-" href="https://github.com/SuperMonster003/AutoJs6/">GitHub - 应用项目地址</a></li>
<li><a class="nav-https-github-com-SuperMonster003-AutoJs6-Documentation" href="https://github.com/SuperMonster003/AutoJs6-Documentation">GitHub - 文档项目地址</a></li>
</ul>
</div>
<div id="column1" data-id="http" class="interior">
<header>
<h1>Auto.js 4.1.0 文档</h1>
<div id="gtoc">
<p>
<a href="index.html" name="toc">索引</a> |
<a href="all.html">查看全部</a>
</p>
</div>
<hr>
</header>
<header>
<h1>AutoJs6 文档 - 6.2.0</h1>
<div id="gtoc">
<p class="index">
<a href="index.html" name="toc">索引</a> |
<a href="all.html">查看全部</a>
</p>
</div>
<hr>
</header>
<div id="toc">
<h2>目录</h2>
<ul>
<li><span class="stability_2"><a href="#http_http">HTTP</a></span><ul>
<div id="toc">
<h2>目录</h2>
<ul>
<li><span class="stability_undefined"><a href="#http_http">HTTP</a></span><ul>
<li><span class="stability_undefined"><a href="#http_http_get_url_options_callback">http.get(url[, options, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#http_http_post_url_data_options_callback">http.post(url, data[, options, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#http_http_postjson_url_data_options_callback">http.postJson(url[, data, options, callback])</a></span></li>
@@ -94,18 +148,23 @@
</li>
</ul>
</div>
</div>
<div id="apicontent">
<h1>HTTP<span><a class="mark" href="#http_http" id="http_http">#</a></span></h1>
<div class="api_stability api_stability_2"><a href="documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p>http模块提供一些进行http请求的函数。</p>
<div id="apicontent">
<h1>HTTP<span><a class="mark" href="#http_http" id="http_http">#</a></span></h1>
<hr>
<p style="font: italic 1em sans-serif; color: #78909C">此章节待补充或完善...</p>
<p style="font: italic 1em sans-serif; color: #78909C">Marked by SuperMonster003 on Oct 22, 2022.</p>
<hr>
<p>http模块提供一些进行http请求的函数.</p>
<h2>http.get(url[, options, callback])<span><a class="mark" href="#http_http_get_url_options_callback" id="http_http_get_url_options_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>url</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 请求的URL地址需要以&quot;<a href="http://&quot;或&quot;https://&quot;开头。如果url没有以&quot;http://&quot;开头,则默认为&quot;http://&quot;。">http://&quot;&quot;https://&quot;开头如果url没有以&quot;http://&quot;开头则默认为&quot;http://&quot;</a></li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 请求选项参见[http.request()][]</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调函数,可选,其参数是一个[Response][]对象如果不加回调函数则该请求将阻塞、同步地执行</li>
<li><code>url</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } 请求的URL地址, 需要以&quot;http://&quot;&quot;https://&quot;开头. 如果url没有以&quot;http://&quot;开头, 则默认为&quot;http://&quot;.</li>
<li><code>options</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> } 请求选项. 参见[http.request()][].</li>
<li><code>callback</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">Function</a> } 回调函数, 可选, 其参数是一个[Response][]对象. 如果不加回调函数, 则该请求将阻塞、同步地执行.</li>
</ul>
</div><p>对地址url进行一次HTTP GET 请求如果没有回调函数则在请求完成或失败时返回此次请求的响应(参见[Response][])</p>
</div><p>对地址url进行一次HTTP GET 请求. 如果没有回调函数, 则在请求完成或失败时返回此次请求的响应(参见[Response][]).</p>
<p>最简单GET请求如下:</p>
<pre><code>console.show();
var r = http.get(&quot;www.baidu.com&quot;);
@@ -121,7 +180,7 @@ http.get(&quot;www.baidu.com&quot;, {}, function(res, err){
log(&quot;code = &quot; + res.statusCode);
log(&quot;html = &quot; + res.body.string());
});
</code></pre><p>如果要增加HTTP头部信息则在options参数中添加例如:</p>
</code></pre><p>如果要增加HTTP头部信息, 则在options参数中添加, 例如:</p>
<pre><code>console.show();
var r = http.get(&quot;www.baidu.com&quot;, {
headers: {
@@ -144,13 +203,13 @@ if(res.statusCode != 200){
}
</code></pre><h2>http.post(url, data[, options, callback])<span><a class="mark" href="#http_http_post_url_data_options_callback" id="http_http_post_url_data_options_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>url</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 请求的URL地址需要以&quot;<a href="http://&quot;或&quot;https://&quot;开头。如果url没有以&quot;http://&quot;开头,则默认为&quot;http://&quot;。">http://&quot;&quot;https://&quot;开头如果url没有以&quot;http://&quot;开头则默认为&quot;http://&quot;</a></li>
<li><code>data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> POST数据</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 请求选项</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调,其参数是一个[Response][]对象如果不加回调参数则该请求将阻塞、同步地执行</li>
<li><code>url</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } 请求的URL地址, 需要以&quot;http://&quot;&quot;https://&quot;开头. 如果url没有以&quot;http://&quot;开头, 则默认为&quot;http://&quot;.</li>
<li><code>data</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } | { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> } POST数据.</li>
<li><code>options</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> } 请求选项.</li>
<li><code>callback</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">Function</a> } 回调, 其参数是一个[Response][]对象. 如果不加回调参数, 则该请求将阻塞、同步地执行.</li>
</ul>
</div><p>对地址url进行一次HTTP POST 请求如果没有回调函数则在请求完成或失败时返回此次请求的响应(参见[Response][])</p>
<p>其中POST数据可以是字符串或键值对具体含义取决于options.contentType的值默认为&quot;application/x-www-form-urlencoded&quot;(表单提交), 这种方式是JQuery的ajax函数的默认方式</p>
</div><p>对地址url进行一次HTTP POST 请求. 如果没有回调函数, 则在请求完成或失败时返回此次请求的响应(参见[Response][]).</p>
<p>其中POST数据可以是字符串或键值对. 具体含义取决于options.contentType的值. 默认为&quot;application/x-www-form-urlencoded&quot;(表单提交), 这种方式是JQuery的ajax函数的默认方式.</p>
<p>一个模拟表单提交登录淘宝的例子如下:</p>
<pre><code>var url = &quot;https://login.taobao.com/member/login.jhtml&quot;;
var username = &quot;你的用户名&quot;;
@@ -167,13 +226,13 @@ if(html.contains(&quot;页面跳转中&quot;)){
}
</code></pre><h2>http.postJson(url[, data, options, callback])<span><a class="mark" href="#http_http_postjson_url_data_options_callback" id="http_http_postjson_url_data_options_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>url</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 请求的URL地址需要以&quot;<a href="http://&quot;或&quot;https://&quot;开头。如果url没有以&quot;http://&quot;开头,则默认为&quot;http://&quot;。">http://&quot;&quot;https://&quot;开头如果url没有以&quot;http://&quot;开头则默认为&quot;http://&quot;</a></li>
<li><code>data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> POST数据</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 请求选项</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调,其参数是一个[Response][]对象如果不加回调参数则该请求将阻塞、同步地执行</li>
<li><code>url</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } 请求的URL地址, 需要以&quot;http://&quot;&quot;https://&quot;开头. 如果url没有以&quot;http://&quot;开头, 则默认为&quot;http://&quot;.</li>
<li><code>data</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> } POST数据.</li>
<li><code>options</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> } 请求选项.</li>
<li><code>callback</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">Function</a> } 回调, 其参数是一个[Response][]对象. 如果不加回调参数, 则该请求将阻塞、同步地执行.</li>
</ul>
</div><p>以JSON格式向目标Url发起POST请求如果没有回调函数则在请求完成或失败时返回此次请求的响应(参见[Response][])</p>
<p>JSON格式指的是将会调用<code>JSON.stringify()</code>把data对象转换为JSON字符串并在HTTP头部信息中把&quot;Content-Type&quot;属性置为&quot;application/json&quot;这种方式是AngularJS的ajax函数的默认方式</p>
</div><p>以JSON格式向目标Url发起POST请求. 如果没有回调函数, 则在请求完成或失败时返回此次请求的响应(参见[Response][]).</p>
<p>JSON格式指的是, 将会调用<code>JSON.stringify()</code>把data对象转换为JSON字符串, 并在HTTP头部信息中把&quot;Content-Type&quot;属性置为&quot;application/json&quot;. 这种方式是AngularJS的ajax函数的默认方式.</p>
<p>一个调用图灵机器人接口的例子如下:</p>
<pre><code>var url = &quot;http://www.tuling123.com/openapi/api&quot;;
r = http.postJson(url, {
@@ -184,34 +243,34 @@ r = http.postJson(url, {
toastLog(r.body.string());
</code></pre><h2>http.postMultipart(url, files[, options, callback])<span><a class="mark" href="#http_http_postmultipart_url_files_options_callback" id="http_http_postmultipart_url_files_options_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>url</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 请求的URL地址需要以&quot;<a href="http://&quot;或&quot;https://&quot;开头。如果url没有以&quot;http://&quot;开头,则默认为&quot;http://&quot;。">http://&quot;&quot;https://&quot;开头如果url没有以&quot;http://&quot;开头则默认为&quot;http://&quot;</a></li>
<li><code>files</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> POST数据</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 请求选项</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调,其参数是一个<code>Response</code>对象如果不加回调参数则该请求将阻塞、同步地执行</li>
<li><code>url</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } 请求的URL地址, 需要以&quot;http://&quot;&quot;https://&quot;开头. 如果url没有以&quot;http://&quot;开头, 则默认为&quot;http://&quot;.</li>
<li><code>files</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> } POST数据.</li>
<li><code>options</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> } 请求选项.</li>
<li><code>callback</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">Function</a> } 回调, 其参数是一个<code>Response</code>对象. 如果不加回调参数, 则该请求将阻塞、同步地执行.</li>
</ul>
</div><p>向目标地址发起类型为multipart/form-data的请求通常用于文件上传等), 其中files参数是<span class="type">&lt;name1: value1, name2: value2, ...&gt;</span>的键值对value的格式可以是以下几种情况</p>
</div><p>向目标地址发起类型为multipart/form-data的请求通常用于文件上传等), 其中files参数是{ <span class="type">name1: value1, name2: value2, ...</span> }的键值对, value的格式可以是以下几种情况</p>
<ol>
<li><code>string</code></li>
<li>文件类型即open()返回的类型</li>
<li>文件类型, 即open()返回的类型</li>
<li>[fileName, filePath]</li>
<li>[fileName, mimeType, filePath]</li>
</ol>
<p>其中1属于非文件参数2、3、4为文件参数举个例子最简单的文件上传的请求为:</p>
<p>其中1属于非文件参数, 2、3、4为文件参数. 举个例子, 最简单的文件上传的请求为:</p>
<pre><code>var res = http.postMultipart(url, {
file: open(&quot;/sdcard/1.txt&quot;)
});
log(res.body.string());
</code></pre><p>如果使用格式2则代码为</p>
</code></pre><p>如果使用格式2, 则代码为</p>
<pre><code>var res = http.postMultipart(url, {
file: [&quot;1.txt&quot;, &quot;/sdcard/1.txt&quot;]
});
log(res.body.string());
</code></pre><p>如果使用格式3则代码为</p>
</code></pre><p>如果使用格式3, 则代码为</p>
<pre><code>var res = http.postMultipart(url, {
file: [&quot;1.txt&quot;, &quot;text/plain&quot;, &quot;/sdcard/1.txt&quot;]
});
log(res.body.string());
</code></pre><p>如果使用格式2的同时要附带非文件参数&quot;appId=abcdefghijk&quot;则为:</p>
</code></pre><p>如果使用格式2的同时要附带非文件参数&quot;appId=abcdefghijk&quot;, 则为:</p>
<pre><code>var res = http.postMultipart(url, {
appId: &quot;adcdefghijk&quot;,
file: open(&quot;/sdcard/1.txt&quot;)
@@ -219,33 +278,33 @@ log(res.body.string());
log(res.body.string());
</code></pre><h2>http.request(url[, options, callback])<span><a class="mark" href="#http_http_request_url_options_callback" id="http_http_request_url_options_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>url</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 请求的URL地址需要以&quot;<a href="http://&quot;或&quot;https://&quot;开头。如果url没有以&quot;http://&quot;开头,则默认为&quot;http://&quot;。">http://&quot;&quot;https://&quot;开头如果url没有以&quot;http://&quot;开头则默认为&quot;http://&quot;</a></li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 请求选项参见[http.buildRequest()][]</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调,其参数是一个[Response][]对象如果不加回调参数则该请求将阻塞、同步地执行</li>
<li><code>url</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } 请求的URL地址, 需要以&quot;http://&quot;&quot;https://&quot;开头. 如果url没有以&quot;http://&quot;开头, 则默认为&quot;http://&quot;.</li>
<li><code>options</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> } 请求选项. 参见[http.buildRequest()][].</li>
<li><code>callback</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">Function</a> } 回调, 其参数是一个[Response][]对象. 如果不加回调参数, 则该请求将阻塞、同步地执行.</li>
</ul>
</div><p>对目标地址url发起一次HTTP请求如果没有回调函数则在请求完成或失败时返回此次请求的响应(参见[Response][])</p>
</div><p>对目标地址url发起一次HTTP请求. 如果没有回调函数, 则在请求完成或失败时返回此次请求的响应(参见[Response][]).</p>
<p>选项options可以包含以下属性</p>
<ul>
<li><code>headers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 键值对形式的HTTP头部信息有关HTTP头部信息参见<a href="http://www.runoob.com/http/http-header-fields.html">菜鸟教程HTTP响应头信息</a></li>
<li><code>method</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> HTTP请求方法包括&quot;GET&quot;, &quot;POST&quot;, &quot;PUT&quot;, &quot;DELET&quot;, &quot;PATCH&quot;</li>
<li><code>contentType</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> HTTP头部信息中的&quot;Content-Type&quot;, 表示HTTP请求的内容类型例如&quot;text/plain&quot;, &quot;application/json&quot;更多信息参见<a href="http://www.runoob.com/http/http-content-type.html">菜鸟教程HTTP contentType</a></li>
<li><code>body</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> HTTP请求的内容可以是一个字符串也可以是一个字节数组;或者是一个以<a href="https://github.com/square/okio/blob/master/okio/src/main/java/okio/BufferedSink.java">BufferedSink</a>为参数的函数</li>
<li><code>headers</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> } 键值对形式的HTTP头部信息. 有关HTTP头部信息, 参见<a href="http://www.runoob.com/http/http-header-fields.html">菜鸟教程HTTP响应头信息</a>.</li>
<li><code>method</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } HTTP请求方法. 包括&quot;GET&quot;, &quot;POST&quot;, &quot;PUT&quot;, &quot;DELET&quot;, &quot;PATCH&quot;.</li>
<li><code>contentType</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } HTTP头部信息中的&quot;Content-Type&quot;, 表示HTTP请求的内容类型. 例如&quot;text/plain&quot;, &quot;application/json&quot;. 更多信息参见<a href="http://www.runoob.com/http/http-content-type.html">菜鸟教程HTTP contentType</a>.</li>
<li><code>body</code> { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } | { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">Array</a> } | { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">Function</a> } HTTP请求的内容. 可以是一个字符串, 也可以是一个字节数组;或者是一个以<a href="https://github.com/square/okio/blob/master/okio/src/main/java/okio/BufferedSink.java/">BufferedSink</a>为参数的函数.</li>
</ul>
<p>该函数是get, post, postJson等函数的基础函数因此除非是PUT, DELET等请求或者需要更高定制的HTTP请求否则直接使用get, post, postJson等函数会更加方便</p>
<p>该函数是get, post, postJson等函数的基础函数. 因此除非是PUT, DELET等请求, 或者需要更高定制的HTTP请求, 否则直接使用get, post, postJson等函数会更加方便.</p>
<h1>Response<span><a class="mark" href="#http_response" id="http_response">#</a></span></h1>
<p>HTTP请求的响应</p>
<p>HTTP请求的响应.</p>
<h2>Response.statusCode<span><a class="mark" href="#http_response_statuscode" id="http_response_statuscode">#</a></span></h2>
<div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li>{ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">number</a> }</li>
</ul>
</div><p>当前响应的HTTP状态码例如200(OK), 404(Not Found)等</p>
<p>有关HTTP状态码的信息参见<a href="http://www.runoob.com/http/http-status-codes.html">菜鸟教程HTTP状态码</a></p>
</div><p>当前响应的HTTP状态码. 例如200(OK), 404(Not Found)等.</p>
<p>有关HTTP状态码的信息, 参见<a href="http://www.runoob.com/http/http-status-codes.html">菜鸟教程HTTP状态码</a>.</p>
<h2>Response.statusMessage<span><a class="mark" href="#http_response_statusmessage" id="http_response_statusmessage">#</a></span></h2>
<div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> </li>
<li>{ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> }</li>
</ul>
</div><p>当前响应的HTTP状态信息例如&quot;OK&quot;, &quot;Bad Request&quot;, &quot;Forbidden&quot;</p>
<p>有关HTTP状态码的信息参见<a href="http://www.runoob.com/http/http-status-codes.html">菜鸟教程HTTP状态码</a></p>
</div><p>当前响应的HTTP状态信息. 例如&quot;OK&quot;, &quot;Bad Request&quot;, &quot;Forbidden&quot;.</p>
<p>有关HTTP状态码的信息, 参见<a href="http://www.runoob.com/http/http-status-codes.html">菜鸟教程HTTP状态码</a>.</p>
<p>例子:</p>
<pre><code>var res = http.get(&quot;www.baidu.com&quot;);
if(res.statusCode &gt;= 200 &amp;&amp; res.statusCode &lt; 300){
@@ -257,10 +316,10 @@ if(res.statusCode &gt;= 200 &amp;&amp; res.statusCode &lt; 300){
}
</code></pre><h2>Response.headers<span><a class="mark" href="#http_response_headers" id="http_response_headers">#</a></span></h2>
<div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
<li>{ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> }</li>
</ul>
</div><p>当前响应的HTTP头部信息该对象的键是响应头名称值是各自的响应头值 所有响应头名称都是小写的(吗)</p>
<p>有关HTTP头部信息参见<a href="http://www.runoob.com/http/http-header-fields.html">菜鸟教程HTTP响应头信息</a></p>
</div><p>当前响应的HTTP头部信息. 该对象的键是响应头名称, 值是各自的响应头值. 所有响应头名称都是小写的(吗).</p>
<p>有关HTTP头部信息, 参见<a href="http://www.runoob.com/http/http-header-fields.html">菜鸟教程HTTP响应头信息</a>.</p>
<p>例子:</p>
<pre><code>console.show();
var res = http.get(&quot;www.qq.com&quot;);
@@ -270,37 +329,41 @@ for(var headerName in res.headers){
}
</code></pre><h2>Response.body<span><a class="mark" href="#http_response_body" id="http_response_body">#</a></span></h2>
<div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
<li>{ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> }</li>
</ul>
</div><p>当前响应的内容他有以下属性和函数:</p>
</div><p>当前响应的内容. 他有以下属性和函数:</p>
<ul>
<li>bytes() <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> 以字节数组形式返回响应内容</li>
<li>string() <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 以字符串形式返回响应内容</li>
<li>json() <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 把响应内容作为JSON格式的数据并调用JSON.parse返回解析后的对象</li>
<li>contentType <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 当前响应的内容类型</li>
<li>bytes() { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">Array</a> } 以字节数组形式返回响应内容</li>
<li>string() { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } 以字符串形式返回响应内容</li>
<li>json() { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">Object</a> } 把响应内容作为JSON格式的数据并调用JSON.parse, 返回解析后的对象</li>
<li>contentType { <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> } 当前响应的内容类型</li>
</ul>
<h2>Response.request<span><a class="mark" href="#http_response_request" id="http_response_request">#</a></span></h2>
<div class="signature"><ul>
<li><span class="type">&lt;Request&gt;</span>
当前响应所对应的请求参见[Request][]</li>
<li>{ <span class="type">Request</span> }
当前响应所对应的请求. 参见[Request][].</li>
</ul>
</div><h2>Response.url<span><a class="mark" href="#http_response_url" id="http_response_url">#</a></span></h2>
<div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a>
当前响应所对应的请求URL</li>
<li>{ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">number</a> }
当前响应所对应的请求URL.</li>
</ul>
</div><h2>Response.method<span><a class="mark" href="#http_response_method" id="http_response_method">#</a></span></h2>
<div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a>
当前响应所对应的HTTP请求的方法例如&quot;GET&quot;, &quot;POST&quot;, &quot;PUT&quot;</li>
<li>{ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">string</a> }
当前响应所对应的HTTP请求的方法. 例如&quot;GET&quot;, &quot;POST&quot;, &quot;PUT&quot;.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<script src="assets/sh_main.js"></script>
<script src="assets/sh_javascript.min.js"></script>
<script>highlight(undefined, undefined, 'pre');</script>
<!-- __TRACKING__ -->
</div>
<script src="assets/sh_javascript.js"></script>
<script src="assets/sh_java.js"></script>
<script src="assets/sh_main.js"></script>
<script>
highlight(void 0, void 0, 'pre');
highlight(void 0, void 0, 'tt');
</script>
<!-- __TRACKING__ -->
</body>
</html>