473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Why can IE return a web page but TcpClient cannot?

Hi,

I have come across a rather bizarre problem using the TcpClient to
retrieve a web page. I use the TcpClient in conjunction with a
StreamWriter to write a HTTP request to the web site. The web server
returns either a 301, 302 or 404 code indicating that the page could
not be found or has been redirected. If I issue the same URL using
Internet Explorer (IE), it does retrieve the page.

I then used a HTTP sniffer program to see what was really going out on
the line. The sniffer shows exactly the same HTTP headers being sent
out using either my program or IE. They are exact in both
case-sensitivity, size and content. I can't figure this out. I have
thought that maybe the HTTP request being sent out to the web server
is too slow. I used the Flush method, set the linguiring state and
tried a number of other things, but the web server always comes back
with 404. Sometimes it even comes back with a 301 or 302. Yet IE is
consistently able to download the file.

I've deleted cookies and the cache but it doesn't help.

What gives??

Here is a partial amount of my code:

----------------------------------------------

TcpClient tcp = new TcpClient();
tcp.Connect(cnn.law.printthis.clickability.com, 80);

-- Tried the following to no avail.
// tcp.NoDelay = true;
// LingerOption tcpClientLingerOption = new LingerOption(false,0);
// tcp.LingerState = tcpClientLingerOption;

NetworkStream networkStream = tcp.GetStream();
StreamWriter streamWriter = new StreamWriter(networkStream);

-- Tried the following to no avail.
// streamWriter.AutoFlush = true;

// Note: there are no line breaks if you are viewing this as posted in
a newsgroup (Google, etc).
string line = @"GET
/pt/cpt?action=cpt&title=CNN.com+-+Malvo+gets+life+sentence+in%A0sniper+killing+-+Oct+26%2C+2004&expire=-1&urlID=12081313&fb=Y&url=http%3A%2F%2Fwww.cnn.com %2F2004%2FLAW%2F10%2F26%2Fmalvo.plea%2Findex.html& partnerID=2013
HTTP/1.1" + "\r\n" +
@"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-powerpoint,
application/vnd.ms-excel, application/msword, */*" + "\r\n" +
@"Accept-Language: en-us" + "\r\n" +
@"Accept-Encoding: gzip, deflate" + "\r\n" +
@"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.0; .NET CLR 1.1.4322)" + "\r\n" +
@"Host: cnn.law.printthis.clickability.com" + "\r\n" +
@"Connection: Keep-Alive" + "\r\n\r\n";

streamWriter.Write(line);
streamWriter.Flush();
// Even tried using a StreamReader instead of a NetworkStream, but to
no avail.
int bytesRead = networkStream.Read(buffer, 0, bytesToRead);
string packet = Encoding.GetEncoding(1252).GetString(buffer, 0,
bytesRead);
streamWriter.Close();
Thanks,
Johann Blake
Jul 21 '05 #1
1 1991
Hi Johann,
Hi,

I have come across a rather bizarre problem using the TcpClient to
retrieve a web page. I use the TcpClient in conjunction with a
StreamWriter to write a HTTP request to the web site. The web server
returns either a 301, 302 or 404 code indicating that the page could
not be found or has been redirected. If I issue the same URL using
Internet Explorer (IE), it does retrieve the page.


301 and 302 are redirects. You have to follew them to
get the right page.

But why on earth don't you use the WebClient oder HttpWebRequest??

bye
Rob
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Don | last post by:
How do I have the server-side php script open up a new client window, rather than having it return to the client page that invoked the php script in the first place? I want to preserve the original...
2
by: Guy Hocking | last post by:
Hi there, First of all my apologies for seeming nieve and perhaps ignorant, i am new to ASP so forgive me. The Problem - I have an ASP page that has a number of list boxes in a form. These...
1
by: Johann Blake | last post by:
Hi, I have come across a rather bizarre problem using the TcpClient to retrieve a web page. I use the TcpClient in conjunction with a StreamWriter to write a HTTP request to the web site. The...
7
by: David Dvali | last post by:
How can I check if TcpClient is connected (or not connected)?
4
by: Sebho | last post by:
Hello, i made an app that use sockets, based on this sample : http://www.microsoft.com/downloads/details.aspx?FamilyId=4B3215C0-62E7-4B84-9944-7582B8CD0125&displaylang=en i'have a problem, i...
1
by: bennett | last post by:
I'm trying to write an ASPX page that uses an OleDbDataAdapter to get data from a SQL Server database. When I test the connection, it returns success, and when I preview the data using the...
8
by: pickedaname | last post by:
I work for a telecom company. We need to get data from our 5ESS switches to be consumed by a .NET app. The data I am getting back is incomplete. For example, the beginning of the first line recvd...
0
by: King Coffee | last post by:
Hi I created a ASP.NET page with a textbox and button, to perform a search. When I click the button, a gridview pops up. The gridview contains a button link to anther page. When I'm finish with...
4
pradeepjain
by: pradeepjain | last post by:
hii guys i have a small problem.i have a page with parameters passed in url .i use POST method in the page and action=PHP_SELF . After submissions i want to return to same page .But the parameters...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.