Reading data from Browser

Hi Experts,

I would like to know the possible ways to do the following.

I have a third party website to which I pass argument.

Something like this

This website returns data in xml.

So what I want to do is read the xml that is returned when the url is hit.

How can I read the result returned?

Thanks in advance.
LVL 21
Obadiah ChristopherAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rahul Goel ITILSenior Consultant - DeloitteCommented:

string lcUrl = "";
// *** Establish the request 
HttpWebRequest loHttp = 
     (HttpWebRequest) WebRequest.Create(lcUrl);
// *** Set properties
loHttp.Timeout = 10000;     // 10 secs
loHttp.UserAgent = "Code Sample Web Client";
// *** Retrieve request info headers
HttpWebResponse loWebResponse = (HttpWebResponse) loHttp.GetResponse();
Encoding enc = Encoding.GetEncoding(1252);  // Windows default Code Page
StreamReader loResponseStream = 
   new StreamReader(loWebResponse.GetResponseStream(),enc);
string lcHtml = loResponseStream.ReadToEnd();

Open in new window

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Rahul Goel ITILSenior Consultant - DeloitteCommented:

Does it contains proxy settings also??
Obadiah ChristopherAuthor Commented:

I'll check and revert.
Obadiah ChristopherAuthor Commented:
Ya proxy will be there. Would there a change in that case?
Rahul Goel ITILSenior Consultant - DeloitteCommented:
Yeah there will be some change in the code:

WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials; 
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(""); 
            //Both works 
            req.Proxy.Credentials = CredentialCache.DefaultCredentials; 
            //req.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials; 
            WebResponse rsp = req.GetResponse(); 
            Stream s = rsp.GetResponseStream(); 
            StreamReader r = new StreamReader(s); 

Open in new window

Hamid HassanCommented:
try this code and after that u can get your required xml and use it...
string link= ""; 
WebRequest req = WebRequest.Create(link);
WebResponse res= req.GetResponse(); 
StreamReader stream = new StreamReader(res.GetResponseStream(),Encoding.Default);
string body = stream.ReadToEnd();

Open in new window


Below url will help you solve your problem.
Obadiah ChristopherAuthor Commented:
Sorry for closing the question late. But the response time of the experts was great.
Thanks once again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.