302 响应 GET 请求在 testcafe 中使用 .request()

问题描述 投票:0回答:0

我的代码如下,我正在尝试一个非常简单的 GET 请求:

  const response = await t.request({
  url:'https://mailsac.com/api/addresses/[email protected]/messages',
  method: 'GET',
  rawResponse: true,
  headers: {'Mailsac-Key': 'key-to-the-api'}
  });
  console.log(response);

为此,我得到了 302“找到”的响应。这意味着我被重定向了。

但它确实适用于

fetch()
。我可以从那里拉出一个神奇的链接:

  fetch('https://mailsac.com/api/addresses/[email protected]/messages', {
    method: 'GET',
    headers: {'Mailsac-Key': 'key-to-the-api'}
    })
      .then(response => response.json())
      .then(json =>  {
        const magicLink = json[0].links[0];
        console.log(magicLink);
         });

我做错了什么吗?如果我想检查

response.body;
,我会得到一个没有数据的糟糕缓冲区。

PD:有没有办法在我的运行中集成 fetch?我似乎不明白如何在 testcafe 运行期间使用 .then() 中的数据。

我正在使用无代理模式,不确定是否相关。

api request testcafe
© www.soinside.com 2019 - 2024. All rights reserved.