0

So I'm doing a GET to my fancy new WebAPI, and one of my parameters is a URL that I escape using encodeURIComponent. In fiddler, the request looks like

GET /api/myapi/myurl/https%3A%2F%2Ft.co%2FkIEnlT8Mvn HTTP/1.1

so that's good.

However, if I look at the request in my Application_BeginRequest, I get

?HttpContext.Current.Request.Url.AbsolutePath 
"/api/myapi/myurl/https:/t.co/kIEnlT8Mvn"

?HttpContext.Current.Request.Url.AbsoluteUri
"http://localhost:23652/api/myapi/myurl/https:/t.co/kIEnlT8Mvn" 

?HttpContext.Current.Request.Url.OriginalString
"http://localhost:23652/api/myapi/myurl/https:/t.co/kIEnlT8Mvn"

?Request.RawUrl
"/api/myapi/myurl/https:/t.co/kIEnlT8Mvn"

So my question is: How can I get the correct URL out of what is sent from the client? I want to get either

A good URL https:SlashSlasht.co/kIEnlT8Mvn (the // changed because SO hates short URLs)

or

https%3A%2F%2Ft.co%2FkIEnlT8Mvn

not https:/t.co/kIEnlT8Mvn

(I've also tried encoding the URL with escape() and encodeURL(), with the same results.)

1 Answer 1

1

A slash is a separator between URL parts, and it looks something inside .NET or MVC or the Routing system is acting strict about this by removing the repeated slash. I don't know if that can be solved or changed.

I think it will work if you can change both the API & the call you are making to use a querystring parameter, something like this:

GET /api/myapi/myurl?address=https%3A%2F%2Ft.co%2FkIEnlT8Mvn HTTP/1.1

public ActionResult MyUrl(string address)
{
    // do your magic here...
}
Sign up to request clarification or add additional context in comments.

1 Comment

yea, that makes sense. I've added code to my existing handler to fixup the URLs I'm getting, but your solution would probably be better. I may just change my whole way of doing it though, because I want it to work with as little goofing around as possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.