I am asking this question primarily because I do not have some ideas clear. I belive I understand how a webserver works but for some reason I am getting different results than expected.
So basically I want to replicate what I do with a real web browser with code.
I have a program called Fiddler that acts as a proxy in order to see all the requests and responses from the web server.
1. So when I open my broser and then goto http://10.10.10.28/tfs:8080 this is what shows up:
——– 
. . . . and this is what fiddler records:

when I click cancel or attempt to log in other requests will be made and fiddler will record more data. I don’t care about that right know I am just interested on simulating this first request.
Anyways so fiddler tels us that the header was:
GET http://10.10.10.28/tfs:8080 HTTP/1.1
Host: 10.10.10.28
Connection: keep-alive
Cache-Control: max-age=0
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
and the response was:
HTTP/1.1 401 Unauthorized
Server: Microsoft-IIS/7.5
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 12.0.0.6421
Date: Fri, 24 Aug 2012 14:36:22 GMT
Content-Length: 0
Proxy-Support: Session-Based-Authentication
2. Finally getting to the fun part the code Now I will like to send the same header and expect to get the same response. For some reason I get a different response!
public static void Main(string[] args)
{
// I save the header bytes recorded from fiddler on a file to make sure I am sending the exact same request
byte[] header = System.IO.File.ReadAllBytes(@"C:\Users\Antonio\Desktop\header");
// create the client
TcpClient client = new TcpClient("10.10.10.28", 8080);
// get the stream so that we can read and write to it
var stream = client.GetStream();
// now that we have the stream wait for the server to respond
WaitForResponse(stream); // waits on a separate thread
// send the request to the header
stream.Write(header, 0, header.Length);
// wait
Console.Read();
}
public static void WaitForResponse(NetworkStream stream)
{
Task.Factory.StartNew(() => {
byte[] buffer = new byte[16384];
int responseLength = stream.Read(buffer, 0, buffer.Length);
string resp = System.Text.UTF8Encoding.UTF8.GetString(buffer, 0, responseLength);
resp = resp; // place breakpoint
});
System.Threading.Thread.Sleep(10); // make sure task starts
}
here is the response that I get:

Why am I getting a different response? I believe web servers use a tcp connection to send pages to clients. why is this approach that I am taking not working? Also why is fiddler not recording anything when I send the request to the web-server from code? How does Google chrome connect to the web server? I would bet that the chrome browser is establishing also a tcp connection with the web server.
In your example, you connect to port 8080 and request the URL
http://10.10.10.28/tfs:8080. So you connect to port 8080 and then request something from port 80. This causes the response ofBad Request.