Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GETting a URL with an url-encoded slash

I want to send a HTTP GET to http://example.com/%2F. My first guess would be something like this:

using (WebClient webClient = new WebClient()) {   webClient.DownloadData("http://example.com/%2F"); } 

Unfortunately, I can see that what is actually sent on the wire is:

GET // HTTP/1.1 Host: example.com Connection: Keep-Alive 

So http://example.com/%2F gets translated into http://example.com// before transmitting it.

Is there a way to actually send this GET-request?

The OCSP-protocol mandates sending the url-encoding of a base-64-encoding when using OCSP over HTTP/GET, so it is necessary to send an actual %2F rather than an '/' to be compliant.

EDIT:

Here is the relevant part of the OCSP protocol standard (RFC 2560 Appendix A.1.1):

An OCSP request using the GET method is constructed as follows:

GET {url}/{url-encoding of base-64 encoding of the DER encoding of the OCSPRequest}

I am very open to other readings of this, but I cannot see what else could be meant.

like image 711
Rasmus Faber Avatar asked Apr 23 '09 10:04

Rasmus Faber


People also ask

Is %2F a slash?

Encoded forward slash (%2F) in parameter not routing correctly #22125.

How do you represent a slash in a URL?

A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. The trailing slash is generally used to distinguish a directory which has the trailing slash from a file that does not have the trailing slash.

What does %20 in a URL mean?

A space is assigned number 32, which is 20 in hexadecimal. When you see “%20,” it represents a space in an encoded URL, for example, http://www.example.com/products%20and%20services.html.


1 Answers

This is a terrible hack, bound to be incompatible with future versions of the framework and so on.

But it works!

(on my machine...)

Uri uri = new Uri("http://example.com/%2F"); ForceCanonicalPathAndQuery(uri); using (WebClient webClient = new WebClient()) {   webClient.DownloadData(uri); }  void ForceCanonicalPathAndQuery(Uri uri){   string paq = uri.PathAndQuery; // need to access PathAndQuery   FieldInfo flagsFieldInfo = typeof(Uri).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic);   ulong flags = (ulong) flagsFieldInfo.GetValue(uri);   flags &= ~((ulong) 0x30); // Flags.PathNotCanonical|Flags.QueryNotCanonical   flagsFieldInfo.SetValue(uri, flags); } 
like image 154
Rasmus Faber Avatar answered Oct 09 '22 21:10

Rasmus Faber