编程语言

  • C7_468666
    了解作者
  • 3.6MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-18 04:54
    上传日期
编程语言
ProgramacionIv-master.zip
内容介绍
<div align="center"> <br> <br> <br> <br> <br> <p align="center">Huge thanks to <a href="https://moxy.studio" rel='nofollow' onclick='return false;'><img src="https://sindresorhus.com/assets/thanks/moxy-logo.svg" width="150"></a> for sponsoring me! </p> <br> <br> </div> > Simplified HTTP requests [![Build Status: Linux](https://travis-ci.org/sindresorhus/got.svg?branch=master)](https://travis-ci.org/sindresorhus/got) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/got/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/got?branch=master) [![Downloads](https://img.shields.io/npm/dm/got.svg)](https://npmjs.com/got) [![Install size](https://packagephobia.now.sh/badge?p=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: [![Install size](https://packagephobia.now.sh/badge?p=request)](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" rel='nofollow' onclick='return false;'> <img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" 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
评论
    相关推荐
    • C编程语言
      C编程语言
    • 编程语言教程
      编程语言教程
    • sabre:saber编程语言
      Sabre编程语言 Sabre是一种无废话(:copyright:)编程语言,它会妨碍您的前进。 它旨在“正常工作”,而不会添加不必要和and肿的语言功能。 为什么还要另一种语言? Sabre的目标是成为一种简单的语言,任何人...
    • 编程语言课件
      编程语言,包括编程语言这门课程的课件以及部分课程作业。
    • 编程语言
      编程语言
    • 7中编程语言
      这本书是老外写的,七个星期完成七种编程语言,每种语言的学习方法,如何快速掌握,最后通过自己的学习,来实现编写简单的编程语言的书,CS专业老外必须课用书
    • 编程语言搜索
      编程语言搜索
    • hope编程语言
      Hope是一个早期的函数式编程语言,有助于学习函数式编程和λ演算 Hope is a small functional programming language developed in the 1970s at the University of Edinburgh. It predates Miranda and Haskell and ...
    • mlpl:多语言编程语言
      多语言编程语言MLPL被设想为儿童的入门编程语言。 当今使用的大多数编程语言的问题是它们需要英语和字母表方面的知识。 因此,非英语国家的儿童比母语为英语的儿童有更高的进入障碍。 MLPL背后的想法是用非常简单...
    • Go编程语言
      Google出品的Go语言(1.0.3版)语言手册,英文CHM版本。