当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript got类代码示例

本文整理汇总了TypeScript中got的典型用法代码示例。如果您正苦于以下问题:TypeScript got类的具体用法?TypeScript got怎么用?TypeScript got使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了got类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: test

test('accept header with json option', async (t) => {
    let headers = (await got(s.url, {json: true})).body;
    t.is(headers.accept, 'application/json');

    headers = (await got(s.url, {headers: {accept: ''}, json: true})).body;
    t.is(headers.accept, '');
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:7,代码来源:headers.ts

示例2: got

(async () => {

  const repository = process.argv[2];
  const response = await got(`https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repository}:pull`, {
    json: true
  });
  const token = response.body.token;

  const allTags = await got(`https://index.docker.io/v2/${repository}/tags/list`, {
    headers: {
      Authorization: `Bearer ${token}`
    },
    json: true,
  });

  for (let tag of allTags.body.tags) {
    let digest = await got.head(`https://index.docker.io/v2/${repository}/manifests/${tag}`, {
      headers: {
        Authorization: `Bearer ${token}`,
        Accept: `application/vnd.docker.distribution.manifest.v2+json`,
      },
    });

    console.log(`${tag} ${digest.headers['docker-content-digest']}`);
  }

})();
开发者ID:OddenCreative,项目名称:versionpress,代码行数:27,代码来源:get-dockerhub-digests.ts

示例3: test

test('make requestt o https server with ca', async (t) => {
    const {body} = await got(s.url, {
        strictSSL: true,
        ca: caRootCert,
        headers: {host: 'sindresorhus.com'}
    });
    t.is(body, 'ok');
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:8,代码来源:https.ts

示例4: test

test('timeout option', async (t) => {
    try {
        await got(`${s.url}/404`, {timeout: 1, retries: 0});
        t.fail('Exception was not thrown');
    } catch (err) {
        t.is(err.code, 'ETIMEDOUT');
    }
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:8,代码来源:http.ts

示例5: tmdbRequest

function tmdbRequest(resource: 'movie' | 'tv', id: string) {
  return got(`https://api.themoviedb.org/3/${resource}/${id}`, {
    query: {
      api_key: process.env.TMDB_API_KEY
    },
    json: true
  })
}
开发者ID:xavdid,项目名称:kerfuffle,代码行数:8,代码来源:tmdb.ts

示例6: test

test('should have statusCode in err', async (t) => {
    try {
        await got(`${s.url}/non200-invalid`, {json: true});
        t.fail('Exception was not thrown');
    } catch (err) {
        t.is(err.statusCode, 500);
    }
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:8,代码来源:json.ts

示例7: test

test('throws on endless redirect', async (t) => {
    try {
        await got(`${http.url}/endless`);
        t.fail('Exception was not thrown');
    } catch (err) {
        t.is(err.message, 'Redirected 10 times. Aborting.');
    }
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:8,代码来源:redirects.ts

示例8: test

test('object in options.bodyt reated as querystring', async (t) => {
    const {body} = await got(s.url, {
        body: {
            such: 'wow'
        }
    });
    t.is(body, 'such=wow');
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:8,代码来源:post.ts

示例9: test

test('options.body error message', async (t) => {
    try {
        await got(s.url, {body: () => {}});
        t.fail('Exception was not thrown');
    } catch (err) {
        t.regex(err.message, /options.body must be a ReadableStream, string, Buffer or plain Object/);
    }
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:8,代码来源:error.ts


注:本文中的got类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。