Radzhab  Ahvahsky
Radzhab Ahvahsky

Reputation: 126

How pass url params to route?

I add route to project.All work correct, but if i send normal url as first param its not correctly work.

Get["/{url}/{digit}"

If i send this params to server-all work correctly.

localhost:8888/google.com/2

But if i send param with http://www its not work.

localhost:8888/https://www.google.com/2

How correct pass url param to route? I think it because Nancy think that i send 3 input param.

Upvotes: 1

Views: 244

Answers (3)

narvoxx
narvoxx

Reputation: 807

Since you insist on changing the backend only, you could try using a regex to capture your route

Get["^(?<url>.*<digit>[0-9]+)$"]

This should match any url ending with atleast one number, and put everything before it in url like so:

Get["^(?<url>.*<digit>[0-9]+)$"] = parameters =>
    {
        var url = parameters.url;
        var digit = parameters.digit;
    };

I am currently unable to verify if this works as you want it to though, and to make sure you can adjust this yourself make sure to look into how to write regex

Upvotes: 0

croxy
croxy

Reputation: 4170

You have to encode your url which is send as a paramater:
Use:

var encodedString = Uri.EscapeDataString("https://www.google.com/2");

then your url will look like this and it shouldn't get any errors:

https%3A%2F%2Fwww.google.com%2F2

Sending the request:

localhost:8888/https%3A%2F%2Fwww.google.com%2F2

Or ou can use the

HttpUtility.UrlEncode();

method. For further information have a look at this.

Upvotes: 1

user5024488
user5024488

Reputation:

If you really need to use GET instead of POST try HttpUtility.UrlEncode("https://google.com/2") to urlencode your url.

Upvotes: 1

Related Questions