Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • The .NET world has the System.Uri (I think, off the top of my head) class which will validate and handle uri's for you. Commented Mar 4, 2014 at 16:56
  • While this is true, Uri can be anything -- from mailto: to ftp: to a local destination. Since I want to be sure that it's a http: or https: Uri. Commented Mar 4, 2014 at 17:02
  • System.Uri will tell you that via the Scheme property. See msdn.microsoft.com/en-us/library/… Commented Mar 4, 2014 at 17:07
  • Yes, I know, that's what my method does. Isn't it better to create a generic method out of it? And further: who should validate the URL? Commented Mar 4, 2014 at 17:50
  • IMO opinion the service should validate the URL so that it can return an error describing the misuse. You can't rely on the caller running validation and ensuring it passes you valid parameters. Validation of generic properties should be handled with a generic mechanism. If your language provides you with the construct then use it directly in this code. If it's not available I'd say implement one that can be called statically and call that instead - I.E. treat it as if it was a standard language construct. Commented Mar 4, 2014 at 18:14