473,387 Members | 1,606 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,387 software developers and data experts.

Web client Application in C#

Ola
I need to create a web client code in C# that retrieves data from a web site. In VB I do the following
Set xmlHttp = WScript.CreateObject("Microsoft.XMLHTTP"
Set xmlDom = WScript.CreateObject("Microsoft.XMLDOM"
xmlDom.LoadXml("<DETAILS FirstName=""John"" LastName=""James"" />"
xmlHttp.Open "POST", "http://host/rocet/Purschase.aspx", 0
xmlHttp.Send(xmlDom

A pointer to equivalent process in C# will be appreciated
Ola
Nov 15 '05 #1
5 1941
Just use HttpWebRequest ... works very well ... brief (and incomplete)
example follows :
StringBuilder formatData = new StringBuilder();

//put your post values into the string builder

HttpWebRequest http = (HttpWebRequest)WebRequest.Create(addr);

http.ContentType = "application/x-www-form-urlencoded";

http.ContentLength = formatData.Length;

http.Method = "POST";
Stream strWrite = http.GetRequestStream();

StreamWriter sw = new StreamWriter(strWrite);

sw.Write(formatData.ToString());

sw.Close();

//Now we need to read the data

WebResponse wr = http.GetResponse();

HttpWebResponse httpRes = (HttpWebResponse)wr;

Stream s = httpRes.GetResponseStream();

StreamReader sr = new StreamReader(s,Encoding.ASCII);

ret = sr.ReadToEnd();

sr.Close();

//Debug.WriteLine(ret)

"Ola" <an*******@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
I need to create a web client code in C# that retrieves data from a web site. In VB I do the following: Set xmlHttp = WScript.CreateObject("Microsoft.XMLHTTP")
Set xmlDom = WScript.CreateObject("Microsoft.XMLDOM")
xmlDom.LoadXml("<DETAILS FirstName=""John"" LastName=""James"" />")
xmlHttp.Open "POST", "http://host/rocet/Purschase.aspx", 0
xmlHttp.Send(xmlDom)

A pointer to equivalent process in C# will be appreciated.
Ola.

Nov 15 '05 #2
Ola
What about sending the request in XML and receiving response in XML instead of string data?
Nov 15 '05 #3
Just change your contentType to 'text/xml' and take the returned Stream and
load it into a XmlTextReader and you'll have your xml doc.

Alex
"Ola" <an*******@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
What about sending the request in XML and receiving response in XML

instead of string data?
Nov 15 '05 #4
Ola
Thanks Alex. Couldn't figure out strWrite in your example. Please help clarify - Just learning
StringBuilder postData = new StringBuilder("<CABDETAILS CabNumber='43877' CabSKU='6633' ExpDate='0106' Postal='78052' />")
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("http://Cabplace/Purchase.aspx")
Request.Method="POST"
Request.ContentType="text/xml"
Request.ContentLength = postData.Length
Stream newStream=Request.GetRequestStream()
StreamWriter sw = new StreamWriter(strWrite)
sw.Write(postData.ToString())
sw.Close();
Nov 15 '05 #5
Ola,

In my example, strWrite was the returned 'Stream' object from the call to
the static Request.GetRequestStream().

In your example, strWrite is actually 'newStream'.

Stream newStream=Request.GetRequestStream();
StreamWriter sw = new StreamWriter(newStream); //this is how that line
should look
sw.Write(postData.ToString());
sw.Close();

Good luck!

Alex
"Ola" <mi****@msn.com> wrote in message
news:E6**********************************@microsof t.com...
Thanks Alex. Couldn't figure out strWrite in your example. Please help clarify - Just learning. StringBuilder postData = new StringBuilder("<CABDETAILS CabNumber='43877' CabSKU='6633' ExpDate='0106' Postal='78052' />"); HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("http://Cabplace/Purchase.aspx"); Request.Method="POST";
Request.ContentType="text/xml";
Request.ContentLength = postData.Length;
Stream newStream=Request.GetRequestStream();
StreamWriter sw = new StreamWriter(strWrite);
sw.Write(postData.ToString());
sw.Close();

Nov 15 '05 #6

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

Similar topics

5
by: Matt | last post by:
I think this is the basic concept in ASP server-side development. My boss told me web application is NOT client-server application. I argued with him because browser is the client, and the server...
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
4
by: Prince Kumar | last post by:
I joined a company recently and they have a java program which hangs (does nothing) after a while. This is no way consistent. It could succeed quite a few times and can fail a few other times....
11
by: Timothy Shih | last post by:
Hi, I am having a freezing issue with my application. My application serves several remotable objects, all of which must be initialized before their use. Furthermore, some of them depend on each...
1
by: mandarbansod | last post by:
Hi i m creating a web application which needs an application may b an exe which will run in background at the end of the day n will update some tables in database. while this application will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.