The code below works great if I connect to what seems to be Apache servers, however when I try to connect to my .Net server it throws an error. I am guessing it is a header
I faced an issue, where executing a HEAD-Request threw a FileNotFoundException.
The reason is, that a response to a HEAD does not have a body and therefore a call to getInputStream throws a FileNotFoundException.
So if you are executing a HEAD, you should not try to get the InputStream.