473,396 Members | 2,052 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,396 software developers and data experts.

WebRequest via HTTP with XML-Body

Hello All,

I want to send a HttpRequest to a program running on http://localhost:8080
on my computer. I want to communicate with this programm by sending an
XML-Message and the Response will be also XML. This seams not to be very
difficult, but I cannot handle it.

How can I create such a HTTP-Connection with C#?
Are there any ideas?

Best Regards,
Kai Huener
Nov 16 '05 #1
2 21456
Kai Huener wrote:
Hello All,

I want to send a HttpRequest to a program running on
http://localhost:8080 on my computer. I want to communicate with this
programm by sending an XML-Message and the Response will be also XML.
This seams not to be very difficult, but I cannot handle it.

How can I create such a HTTP-Connection with C#?
Are there any ideas?


Kai, here's a sample method that uses the System.Net.HttpWebRequest/Response
classes. The sample assumes your XML messages should be UTF-8 encoded.

public void PostXml(string url, string xml) {
byte[] bytes = Encoding.UTF8.GetBytes(xml);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";
using (Stream requestStream = request.GetRequestStream()) {
requestStream.Write(bytes, 0, bytes.Length);
}

// This sample only checks whether we get an "OK" HTTP status code back.
// If you must process the XML-based response, you need to read that from
// the response stream.
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
{
if (response.StatusCode != HttpStatusCode.OK) {
string message = String.Format(
"POST failed. Received HTTP {0}",
response.StatusCode);
throw new ApplicationException(message);
}
}
}

Cheers,

--
Joerg Jooss
jo*********@gmx.net
Nov 16 '05 #2
in addition to the exceptional suggestion already provided, I would add that
if you simply create a web service and place it on the web site running on
that port, you will be communicating using XML over HTTP, just as you
request, with a lot more support in C# than rolling your own.

Why not just use a web service?

--- Nick

"Kai Huener" <ma**@kaihuener.de> wrote in message
news:uS**************@TK2MSFTNGP11.phx.gbl...
Hello All,

I want to send a HttpRequest to a program running on http://localhost:8080 on my computer. I want to communicate with this programm by sending an
XML-Message and the Response will be also XML. This seams not to be very
difficult, but I cannot handle it.

How can I create such a HTTP-Connection with C#?
Are there any ideas?

Best Regards,
Kai Huener

Nov 16 '05 #3

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

Similar topics

4
by: Full Decent | last post by:
I want to write a simple C++ backend to a website so I can use XMLHTTPRequest. The server is stateful and cannot be cgi. Is there a simple C++ framework to handle the HTTP communications? I had...
1
by: Cybertof | last post by:
Hello, Is it possible to use ADO.NET to connect to a SQL Server and get back a DatSet as an XML result through HTTP (so the application can pass through firewalls) ? If yes, how to do it ?...
1
by: Mark | last post by:
I'm sending an xml stream through an http connection to my webserver. Since some of the xml data will have the same characters as the 'xml characters'(i.e <,>, etc...), I need the xml to be encoded...
1
by: Steve | last post by:
I'm trying to get a proper response from a web server serving an xml document. I keep getting "<" as the response. Normal web pages return fine, so I must be using the wrong approach. Can anyone...
2
by: darren via AccessMonster.com | last post by:
Hi I've been given a heads up on a task that might coming my way. I don't have full details yet but understand that it involves getting the access application to connect to a web application to...
0
by: Vijaya Kaur Arora | last post by:
Hi, I am trying to create a class with Webrequest and use the data transferred via a webservice. Any pointer to sample code will be useful. Thank you in advance.
2
by: CindyH | last post by:
Hi Trying to get this code to work for http xml post. I need the post to be xml (doc.outerxml) sent in single key name as stream. The following is the post code and code for receiving the request....
2
by: CindyH | last post by:
Hi What would be the best way to post and receive http xml post using vb.net? Thanks, CindyH
6
by: CindyH | last post by:
Hi I'm not sure whether I should send this as a new message or use the one I've been using but... I'm using vb.net 2.0 - My problem is I need to send something like this: 'dim encodedstring =...
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: 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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.