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


TypeScript got.get函数代码示例

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


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

示例1: get

export function get(url: string, headers: any): Promise<any> {
  headers["User-Agent"] = userAgent;
  return got
    .get(url, { headers })
    .then((res: any) => parseJSON(res.body))
    .catch(wrapError);
}
开发者ID:eggyo,项目名称:dang-ai,代码行数:7,代码来源:http.ts

示例2: test

test('promise mode', async (t) => {
    t.is((await got.get(s.url)).body, 'ok');

    try {
        await got.get(`${s.url}/404`);
        t.fail('Exception was not thrown');
    } catch (err) {
        t.is(err.response.body, 'not found');
    }

    try {
        await got.get('.com', {retries: 0});
        t.fail('Exception was not thrown');
    } catch (err) {
        t.truthy(err);
    }
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:17,代码来源:helpers.ts

示例3: getUpdateYaml

async function getUpdateYaml(): Promise<string> {
  const targetUrl = getUpdateCheckUrl();
  const { body } = await get(targetUrl, getGotOptions());

  if (!body) {
    throw new Error('Got unexpected response back from update check');
  }

  return body.toString('utf8');
}
开发者ID:WhisperSystems,项目名称:Signal-Desktop,代码行数:10,代码来源:common.ts

示例4: downloadUpdate

export async function downloadUpdate(
  fileName: string,
  logger: LoggerType
): Promise<string> {
  const baseUrl = getUpdatesBase();
  const updateFileUrl = `${baseUrl}/${fileName}`;

  const signatureFileName = getSignatureFileName(fileName);
  const signatureUrl = `${baseUrl}/${signatureFileName}`;

  let tempDir;
  try {
    tempDir = await createTempDir();
    const targetUpdatePath = join(tempDir, fileName);
    const targetSignaturePath = join(tempDir, getSignatureFileName(fileName));

    logger.info(`downloadUpdate: Downloading ${signatureUrl}`);
    const { body } = await get(signatureUrl, getGotOptions());
    await writeFile(targetSignaturePath, body);

    logger.info(`downloadUpdate: Downloading ${updateFileUrl}`);
    const downloadStream = stream(updateFileUrl, getGotOptions());
    const writeStream = createWriteStream(targetUpdatePath);

    await new Promise((resolve, reject) => {
      downloadStream.on('error', error => {
        reject(error);
      });
      downloadStream.on('end', () => {
        resolve();
      });

      writeStream.on('error', error => {
        reject(error);
      });

      downloadStream.pipe(writeStream);
    });

    return targetUpdatePath;
  } catch (error) {
    if (tempDir) {
      await deleteTempDir(tempDir);
    }
    throw error;
  }
}
开发者ID:WhisperSystems,项目名称:Signal-Desktop,代码行数:47,代码来源:common.ts

示例5: test

test('GET can have body', async (t) => {
    const {body, headers} = await got.get(s.url, {body: 'hi'});
    t.is(body, 'hi');
    t.is(headers.method, 'GET');
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:5,代码来源:post.ts


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