Search code examples
c#webrequest

How to know if my WebRequest is full?


I create a WebRequest in C#:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://myURL");

The URL is a request and may get big. Actually, depending on what the user does, I have no control over the size.

To prevent a case where the request is too long, I'd like to parse it.

Was is the maximum lenght of a string I can use to create a valid WebRequest?


Solution

  • You'll be restricted by the server that receives the request, which will vary by server and configuration. As an example, Apache will DEFAULT to max length of about ~8100 characters, but that is only the default. A good rule of thumb is ~2000 characters, as that is what most browsers will max out at. As for the HTTP spec, it is unbounded, but you will find that any server can limit it as they wish. The Uri will limit it to about ~65k characters as noted in another answer.

    SO question about the max length of Apache URL: What is apache's maximum url length?

    SO question about browser limit: What is the maximum length of a URL in different browsers?