<div align="center">
<br>
<br>
<img width="360" src="media/logo.svg" alt="Got">
<br>
<br>
<br>
<p align="center">Huge thanks to <a href="https://moxy.studio"><img src="https://sindresorhus.com/assets/thanks/moxy-logo.svg" width="150"></a> for sponsoring me!
</p>
<br>
<br>
</div>
> Simplified HTTP requests
[](https://travis-ci.org/sindresorhus/got) [](https://coveralls.io/github/sindresorhus/got?branch=master) [](https://npmjs.com/got) [](https://packagephobia.now.sh/result?p=got)
Got is a human-friendly and powerful HTTP request library.
It was created because the popular [`request`](https://github.com/request/request) package is bloated: [](https://packagephobia.now.sh/result?p=request)
Got is for Node.js. For browsers, we recommend [Ky](https://github.com/sindresorhus/ky).
## Highlights
- [Promise & stream API](#api)
- [Request cancelation](#aborting-the-request)
- [RFC compliant caching](#cache-adapters)
- [Follows redirects](#followredirect)
- [Retries on failure](#retry)
- [Progress events](#onuploadprogress-progress)
- [Handles gzip/deflate](#decompress)
- [Timeout handling](#timeout)
- [Errors with metadata](#errors)
- [JSON mode](#json)
- [WHATWG URL support](#url)
- [Hooks](#hooks)
- [Instances with custom defaults](#instances)
- [Composable](advanced-creation.md#merging-instances)
- [Electron support](#useelectronnet)
- [Used by ~2000 packages and ~500K repos](https://github.com/sindresorhus/got/network/dependents)
- Actively maintained
[Moving from Request?](migration-guides.md)
[See how Got compares to other HTTP libraries](#comparison)
## Install
```
$ npm install got
```
<a href="https://www.patreon.com/sindresorhus">
<img src="https://c5.patreon.com/external/logo/[email protected]" width="160">
</a>
## Usage
```js
const got = require('got');
(async () => {
try {
const response = await got('sindresorhus.com');
console.log(response.body);
//=> '<!doctype html> ...'
} catch (error) {
console.log(error.response.body);
//=> 'Internal server error ...'
}
})();
```
###### Streams
```js
const fs = require('fs');
const got = require('got');
got.stream('sindresorhus.com').pipe(fs.createWriteStream('index.html'));
// For POST, PUT, and PATCH methods `got.stream` returns a `stream.Writable`
fs.createReadStream('index.html').pipe(got.stream.post('sindresorhus.com'));
```
### API
It's a `GET` request by default, but can be changed by using different methods or in the `options`.
#### got(url, [options])
Returns a Promise for a [`response` object](#response) or a [stream](#streams-1) if `options.stream` is set to true.
##### url
Type: `string` `Object`
The URL to request, as a string, a [`https.request` options object](https://nodejs.org/api/https.html#https_https_request_options_callback), or a [WHATWG `URL`](https://nodejs.org/api/url.html#url_class_url).
Properties from `options` will override properties in the parsed `url`.
If no protocol is specified, it will default to `https`.
##### options
Type: `Object`
Any of the [`https.request`](https://nodejs.org/api/https.html#https_https_request_options_callback) options.
###### baseUrl
Type: `string` `Object`
When specified, `url` will be prepended by `baseUrl`.<br>
If you specify an absolute URL, it will skip the `baseUrl`.
Very useful when used with `got.extend()` to create niche-specific Got instances.
Can be a string or a [WHATWG `URL`](https://nodejs.org/api/url.html#url_class_url).
Slash at the end of `baseUrl` and at the beginning of the `url` argument is optional:
```js
await got('hello', {baseUrl: 'https://example.com/v1'});
//=> 'https://example.com/v1/hello'
await got('/hello', {baseUrl: 'https://example.com/v1/'});
//=> 'https://example.com/v1/hello'
await got('/hello', {baseUrl: 'https://example.com/v1'});
//=> 'https://example.com/v1/hello'
```
###### headers
Type: `Object`<br>
Default: `{}`
Request headers.
Existing headers will be overwritten. Headers set to `null` will be omitted.
###### stream
Type: `boolean`<br>
Default: `false`
Returns a `Stream` instead of a `Promise`. This is equivalent to calling `got.stream(url, [options])`.
###### body
Type: `string` `Buffer` `stream.Readable` [`form-data` instance](https://github.com/form-data/form-data)
**Note:** If you provide this option, `got.stream()` will be read-only.
The body that will be sent with a `POST` request.
If present in `options` and `options.method` is not set, `options.method` will be set to `POST`.
The `content-length` header will be automatically set if `body` is a `string` / `Buffer` / `fs.createReadStream` instance / [`form-data` instance](https://github.com/form-data/form-data), and `content-length` and `transfer-encoding` are not manually set in `options.headers`.
###### cookieJar
Type: [`tough.CookieJar` instance](https://github.com/salesforce/tough-cookie#cookiejar)
**Note:** If you provide this option, `options.headers.cookie` will be overridden.
Cookie support. You don't have to care about parsing or how to store them. [Example.](#cookies)
###### encoding
Type: `string` `null`<br>
Default: `'utf8'`
[Encoding](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) to be used on `setEncoding` of the response data. If `null`, the body is returned as a [`Buffer`](https://nodejs.org/api/buffer.html) (binary data).
###### form
Type: `boolean`<br>
Default: `false`
**Note:** If you provide this option, `got.stream()` will be read-only.
**Note:** `body` must be a plain object. It will be converted to a query string using [`(new URLSearchParams(object)).toString()`](https://nodejs.org/api/url.html#url_constructor_new_urlsearchparams_obj).
If set to `true` and `Content-Type` header is not set, it will be set to `application/x-www-form-urlencoded`.
###### json
Type: `boolean`<br>
Default: `false`
**Note:** If you use `got.stream()`, this option will be ignored.
**Note:** `body` must be a plain object or array and will be stringified.
If set to `true` and `Content-Type` header is not set, it will be set to `application/json`.
Parse response body with `JSON.parse` and set `accept` header to `application/json`. If used in conjunction with the `form` option, the `body` will the stringified as querystring and the response parsed as JSON.
###### query
Type: `string` `Object<string, string|number>` [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
Query string that will be added to the request URL. This will override the query string in `url`.
If you need to pass in an array, you can do it using a `URLSearchParams` instance:
```js
const got = require('got');
const query = new URLSearchParams([['key', 'a'], ['key', 'b']]);
got('https://example.com', {query});
console.log(query.toString());
//=> 'key=a&key=b'
```
And if you need a different array format, you could use the [`query-string`](https://github.com/sindresorhus/query-string) package:
```js
const got = require('got');
const queryString = require('query-string');
const query = queryString.stringify({key: ['a', 'b']}, {arrayFormat: 'bracket'});
got('https://example.com', {query});
console.log(query);
//=> 'key[]=a&key[]=b'
```
###### timeout
Type: `number` `Object`
Milliseconds to wait for the server to end the response before aborting the request with [`got.TimeoutError`](#gottimeouterror) error (a.k.a. `request` property). By default, there's no timeout.
This also accepts an `object` with the following fields to constrain the duration of each phase of the request lifecycle:
- `lookup` starts when a socket is assigned and ends when the hostname has been resolved
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
整个项目文件包含以下内容: 1)mongoData : 数据库文件; 2)node_modules : 运行所需模块文件; 3)public : 前端样式文件 4)router : 响应活动的js文件 5)views : html5文件 6)app.aba.js : 服务器运行文件(package.json&package-lock.json) 7)mongodb.js : mongodb数据库方法的封装 三、前端 为了较为快速地完成界面的布局设计,主要使用了bootstrape框架。 在views中主要有12个页面,包括从首页、注册登陆及其他查询、更新数据等活动的界面。 在获取数据发布到前端时使用到了EJS模板引擎。 界面的css文件统一保存在public文件夹中。 四、后端 使用node.js语言和express框架。
资源推荐
资源详情
资源评论

























收起资源包目录





































































































共 2002 条
- 1
- 2
- 3
- 4
- 5
- 6
- 21
资源评论


云哲-吉吉2021
- 粉丝: 4307
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 云计算在后勤中的应用.pptx
- STM32 GUI应用培训:03- STM32 GUI应用软件解决方案详述.pdf
- STM32F2产品技术培训_电源管理及功耗模块(PWR)介绍.pdf
- STM32L4串行同步异步收发器(USART)介绍.pdf
- 2005年研究生入学考试结构力学试卷.doc
- 大学生网络社中教团建设与科学发展路径选择.doc
- 坝体灌浆专项施工方案(0002).doc
- 【STM32MP1线上课程】STM32MP1 online training_12_OpenSTLinux Starte
- STM8L模数转换模块(ADC)介绍.pdf
- 005-技术交底-石材幕墙防雷.doc
- 【STM32U5线上课程】STM32U5 online training_29_CORDIC co-processor.
- 基于unity3d的FPS训练游戏设计与开发.docx
- STM32F0复位(RST)和时钟控制(CLK)模块介绍.pdf
- 北京某大厦基坑降水.支护工程设计.doc
- 电气工程及其自动化专业课电机学期末复习点.doc
- 客户关系管理在旅游电子商务的应用以携程网为例.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
