tags:

views:

239

answers:

3

our application requests a URL from a user however the URL might include information after the .com or .com.uk (any country designation) address ending.

for example the user may provide us with an address;
www.example.com/sample/userbin?form=sl&t=

Of course the above URL is made up and won't work but it illustrates my point.

Our application also stores connection data to enable the application to access the internet through a proxy server etc. It also allows the user to specify the Port number but we note that WebClient does not provide a member for Port Number.

The only other way is to append the port number to the URL but how can we do this when we don't know the URL provided by the user?

+1  A: 

I don't know if this will help you, but ports in URLs come directly after the hostname, preceded by a colon.

Example: (www.example.com on port 8080)

http://www.example.com:8080/
icktoofay
+1  A: 

Why don't you know the domain? If the user has entered a valid URL it matches a pattern like:

//<domain>/path/file/whatever

or

<domain>/path/file/whatever

Add port:

<domain>:<port>/path/file/whatever
Cory Charlton
the domain could be anything .... so it looks like all we need to do is strip out the domain from the URL and append the port.
Trent
Correct just parse the domain based on starting with *// (ie: http://, https://, ftp://, etc) and the next /.
Cory Charlton
A: 

You could split it up by the / or ? for example:

http://google.com|?search=cats
http://google.com|/mail

Where | is the split. The only possible characters to come after a URL are / and ?. So you could do the following:

http://google.com|/mail 

split, then append the port after the domain then append the extra at the end, like so:

http://google.com:8080/mail

I think this is what you mean.

citricsquid
so "/" or "?" are the only characters that will ever come after a domain?
Trent
Pretty sure, unless they already provide a port (which you could check for with :). I've never seen anything else used, but you might want to check the rfc spec.
citricsquid