How to pass a URL in the Parameter of an API

Asked

Viewed 500 times

1

How to pass a URL to an API

public class HTTPController : ControllerBase
{
    [HttpGet("URL={URL}")]
    public JsonResult GETURL(string URL)
    {
    }
}

However when passing for example https://google.pt this does not interpret as parameter

I tried to pass so "http%3A%2F%2Fgoogle.pt" but it does not work in the same

  • How are you doing?

  • http://localhost/HTTP/GETURL/URL=http://google.pt

  • 1

    Forgot to ask controller? Guy put more information ...

  • is called http I’ve updated the code

  • tried so but no localhost/HTTP/GETURL/URL=http%3A%2F%2Fgoogle.pt

1 answer

2


The route generated by your code will be:

/http/URL={paramêtro}

Pass the parameter https://google.pt does not work because it is not possible to pass parameters with / route, if you want to do this, you have to find the parameter somehow.

Anyway recommend to pass it via query string. Your code would look like this:

[HttpGet("[action]")]
public JsonResult GETURL([FromQuery] string URL)

Generated route:

/http/geturl?URL={paramêtro}
  • I encoded so http%3A%2F%2Fgoogle.pt but it didn’t work

  • I tested here and it worked normal encondo. Stay tuned to the route of your action to see if you’re hitting it right. In my answer I set the route your code generates.

  • I used Base64 Encode and functiounou cetinho

Browser other questions tagged

You are not signed in. Login or sign up in order to post.