Postman 如何验证来自API的重定向是否有效
我有一个API方法,需要根据提供的一些输入重定向到URLPostman 如何验证来自API的重定向是否有效,postman,asp.net-core-webapi,http-redirect,asp.net-core-3.0,Postman,Asp.net Core Webapi,Http Redirect,Asp.net Core 3.0,我有一个API方法,需要根据提供的一些输入重定向到URL [ApiController] public class AuthController : ControllerBase { [HttpGet()] public IActionResult GetUrl(string input) { // retrieve a url based on the input string url = GetUrl(input); r
[ApiController]
public class AuthController : ControllerBase
{
[HttpGet()]
public IActionResult GetUrl(string input)
{
// retrieve a url based on the input
string url = GetUrl(input);
return Redirect(url);
}
}
当我使用postman调试这个方法时,我看到检索到了正确的URL,并且调用了重定向。然而,在《邮递员》中,我获得了HTTP404状态。我的问题是:
因此,我认为您正在传递的URL前面不包含
http://
或https://
,ASP.NET正在尝试将您重定向到,而不是重定向到外部站点。尝试在传递给GetUrl
方法的URL前面添加https://
或http://
。然后你应该在邮递员中得到一个200 OK
例如:
using Microsoft.AspNetCore.Mvc;
namespace WebApplication1.Controllers
{
[ApiController]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
[HttpGet]
public IActionResult GetUrl([FromQuery]string url)
{
return Redirect("https://" + url);
}
}
}
在本例中,如果您将
url=google.com
传递给应用程序,您将被重定向到Postman中,并获得200 OK
。您想重定向到外部url还是同一主机上的某个url?重定向到外部url我会回答,我想我发现了您的问题。