473,766 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebResponse contains carriage returns, tab characters, etc?

I'm trying to download a webpage by using the HttpWebRequest. It returns the
html source, however, it contains "\r\n", "\t" etc throughout the text. Is
there a way to return the same HTML as when I navigate to the url in the
browser and do a "View Source"? Or do I have to manually strip these out?
The full code is below where I'm posting the necessary data to simulate a
form post.

HttpWebRequest req = (HttpWebRequest )WebRequest.Cre ate(Url);
req.Method = "POST";
req.UserAgent = "Mozilla/4.0+";
req.ContentType = "applicatio n/x-www-form-urlencoded";

System.Text.ASC IIEncoding encoding = new System.Text.ASC IIEncoding();
byte[] PostBuffer = encoding.GetByt es(PostData);
req.ContentLeng th = PostBuffer.Leng th;
Stream stm = req.GetRequestS tream();
stm.Write(PostB uffer, 0, PostBuffer.Leng th);
stm.Close();

// Get the response.
resp = req.GetResponse () as HttpWebResponse ;
sr = new StreamReader(re sp.GetResponseS tream());

string result = sr.ReadToEnd(); <--returns the source but with carriage
returns etc.
Jul 1 '08 #1
3 2469
I would expect your source to contain CR's and Tabs, this is probably
the way it's being sent. if you see something else in a "view source"
I suspect that's a problem with the browser, not with the request.

so yes, you have to manually strip these out.
Jul 1 '08 #2
"Dave" <Da**@discussio ns.microsoft.co mwrote in message
news:FF******** *************** ***********@mic rosoft.com...
I'm trying to download a webpage by using the HttpWebRequest. It returns
the
html source, however, it contains "\r\n", "\t" etc throughout the text.
Is
there a way to return the same HTML as when I navigate to the url in the
browser and do a "View Source"? Or do I have to manually strip these out?
The full code is below where I'm posting the necessary data to simulate a
form post.

HttpWebRequest req = (HttpWebRequest )WebRequest.Cre ate(Url);
req.Method = "POST";
req.UserAgent = "Mozilla/4.0+";
req.ContentType = "applicatio n/x-www-form-urlencoded";

System.Text.ASC IIEncoding encoding = new System.Text.ASC IIEncoding();
byte[] PostBuffer = encoding.GetByt es(PostData);
req.ContentLeng th = PostBuffer.Leng th;
Stream stm = req.GetRequestS tream();
stm.Write(PostB uffer, 0, PostBuffer.Leng th);
stm.Close();

// Get the response.
resp = req.GetResponse () as HttpWebResponse ;
sr = new StreamReader(re sp.GetResponseS tream());

string result = sr.ReadToEnd(); <--returns the source but with carriage
returns etc.
I have a suspision that you believe the string actually contains \r\n and \t
rather than the controls control code equivalents and that you believe this
because that's what the debugger is showing you. However the debugger shows
you the string in an escaped form that is valid as string literal in C#.

OTH something really bizare is happening.

--
Anthony Jones - MVP ASP/ASP.NET
Jul 1 '08 #3
do u get same results with System.Net.WebC lient? (simpler anyway)

On Jul 2, 1:08*am, Dave <D...@discussio ns.microsoft.co mwrote:
I'm trying to download a webpage by using the HttpWebRequest. *It returns the
html source, however, it contains "\r\n", "\t" etc throughout the text. *Is
there a way to return the same HTML as when I navigate to the url in the
browser and do a "View Source"? Or do I have to manually strip these out? *
The full code is below where I'm posting the necessary data to simulate a
form post.

HttpWebRequest req = (HttpWebRequest )WebRequest.Cre ate(Url);
req.Method = "POST";
req.UserAgent = "Mozilla/4.0+";
req.ContentType = "applicatio n/x-www-form-urlencoded";

System.Text.ASC IIEncoding encoding = new System.Text.ASC IIEncoding();
byte[] PostBuffer = encoding.GetByt es(PostData);
req.ContentLeng th = PostBuffer.Leng th;
Stream stm = req.GetRequestS tream();
stm.Write(PostB uffer, 0, PostBuffer.Leng th);
stm.Close();

// Get the response.
resp = req.GetResponse () as HttpWebResponse ;
sr = new StreamReader(re sp.GetResponseS tream());

string result = sr.ReadToEnd(); <--returns the source but with carriage
returns etc.
Jul 2 '08 #4

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

Similar topics

1
4658
by: Shiperton Henethe | last post by:
Hi Anyone know how to do a MAILTO: such that the "BODY=" parameter contains carriage returns ? e.g. <A HREF="mailto:brochure@webwindows.co.uk?subject=Brochure Request&amp;body=Line1 blah blah Line2 blah blah blah Line3 blah ">
8
46179
by: Steven | last post by:
i need to force a carriage return with a textarea field at X number of characters. anybody know how to do this? tks
4
18699
by: Josh | last post by:
Hi, I'm using System.Data.DataSet.ReadXml to convert some xml from a webservice to a DataSet. The xml looks like: <?xml version="1.0" encoding="UTF-8"?><root><prioritiesTable><description>blah blah blah blah</description></prioritiesTable></root> The important thing here is the which I beleive should be a single
2
4130
by: Andrew Chanter | last post by:
I have a VBA function that returns a string including "vbcr" (VB Carriage Return) to seperate a list into multiple rows, eg Item1 & vbcr & Item2 & vbcr & Item3 This works as planned in the immediate window, producing a list where a Carriage Return follows each item. But when I output the result into either an Access query or form, instead of carriage returns I get little square symbols between each of the items. Is anyone able to tell...
12
5616
by: Nimmy | last post by:
Hi, I have a data file and I want to remove Carriage returns. Any one has any C code/program which does this? I am working on Windows XP machine.....I don't have access to UNIX machine. But I need to send this data file to the Unix machine once I remove the carriage retunrns from my XP machine. Thanks
2
2338
by: Matt Mercer | last post by:
Hi all, I am having a frustration problem, and I have read about 25 newsgroup postings that do not have a satisfying answer :) The problem appears to be common where carriage returns are lost when pulling data from an SQL database. The thing that frustrates me the most, is that when I use Enterprise Manager, the carriage returns ARE THERE. It looks fine until I pull it out.
8
2223
by: TheDude5B | last post by:
Hi, I have some data which is stored in my MySQL database as TEXT. when the data is entered in, it has some carriage returns in it, and this can be seen when querying the data using MySQL Query Browser. I want to then display this text within <p> tags when requested from the database. However, the test is formatted without the carriage returns.
2
9729
by: Bazza Formez | last post by:
I have a bound field in a DetailsView control that displays free form description type data from my SQL database table (typical data is a couple of paragraphs of written product description being held in a single database field of type ntext). This description data typically has various simple control characters in it - ie. new line, carriage returns etc) to make the paragraph more readable. My problem is that these control characters...
7
22985
by: newbtemple | last post by:
Hey all. I'm having a bugger of a time trying to remove carriage returns. I have a large text file with a bunch of little squares. I'm guessing they're carriage returns from what i've googled. They are not standard ascii characters. Anywho, i'de like to get rid of them. I've got a loop that tests this condition: If textCharArray((charPosition) + (133 * rowPosition)) = Environment.NewLine Then textCharArray((charPosition) + (133 *...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8833
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.