473,320 Members | 1,974 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,320 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 21446
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.