[英]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?有没有办法在邮递员中进行测试,还是应该使用其他应用程序?
Automatically follow redirects
in Postman.Automatically follow redirects
设置。example.com/test-page/test01
example.com/test-page/test01
发出请求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.