简体   繁体   English

从 Postman 获取重定向的 URL

[英]Get redirected URL from Postman

I'm currently migrating my old website to a new one and I have just created some url redirect rules to redirect old links to their pages on the new website.我目前正在将我的旧网站迁移到一个新网站,我刚刚创建了一些 url 重定向规则来将旧链接重定向到新网站上的页面。

In order to test these redirect rules I'm using Postman but I can't find any way of getting the redirected url from Postman's scripts documentation .为了测试这些重定向规则,我使用了 Postman,但我找不到任何方法从 Postman 的脚本文档中获取重定向的 url。 REDIRECTED_URL is the url after being processed by the redirect rule. REDIRECTED_URL是重定向规则处理后的url。

Here is my current test:这是我目前的测试:

var root_url = postman.getEnvironmentVariable('root_url');
var oldurl = root_url + postman.getEnvironmentVariable('old_page');
var newurl = root_url + postman.getEnvironmentVariable('new_page');

if (REDIRECTED_URL == newurl)
{
    tests[oldurl + " redirected"] = true;
}
else
{
    tests[oldurl + " failed to redirect"] = false;
}

Is there a way to test this in postman or should I be using another application?有没有办法在邮递员中进行测试,还是应该使用其他应用程序?

  1. Switch off the setting Automatically follow redirects in Postman.关闭 Postman 中的Automatically follow redirects设置。
  2. Do a request to example.com/test-page/test01example.com/test-page/test01发出请求
  3. In the test tab, check if the https status code and the re-direct header are correct:在测试选项卡中,检查 https 状态代码和重定向标头是否正确:
pm.test("Status Code is 301", function () {
    pm.response.to.have.status(301);
});

pm.test("Location-header exists", function () {
    pm.expect(postman.getResponseHeader("Location")).to.eq("example.com/tests/test01");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM