473,699 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 21482
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.Http WebRequest/Response
classes. The sample assumes your XML messages should be UTF-8 encoded.

public void PostXml(string url, string xml) {
byte[] bytes = Encoding.UTF8.G etBytes(xml);
HttpWebRequest request = (HttpWebRequest ) WebRequest.Crea te(url);
request.Method = "POST";
request.Content Length = bytes.Length;
request.Content Type = "text/xml";
using (Stream requestStream = request.GetRequ estStream()) {
requestStream.W rite(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 (HttpWebRespons e response = (HttpWebRespons e) request.GetResp onse())
{
if (response.Statu sCode != HttpStatusCode. OK) {
string message = String.Format(
"POST failed. Received HTTP {0}",
response.Status Code);
throw new ApplicationExce ption(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******** ******@TK2MSFTN GP11.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
2070
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 looked into XML-RPC but I'm not sure if that's the way to go.
1
1366
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 ? (specifying port 80 for input/output request/result, specifying XML required format, etc...) Thanks,
1
2207
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 for the server. For example, is it a standard practice to encode the > characer as &gt; in the xml ? Will this do it ? Dim oEncoder As New System.Text.ASCIIEncoding requestData = oEncoder.GetBytes(xmlString)
1
1082
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 point me in the right direction?
2
1569
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 get quotes. All I have so far is that it may involve http POST requests and XML messaging. We will be provided a user name, password and digital certificate. Whilst I await further information I am simply trying to get an idea of what this...
0
858
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
2194
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. When it hits the "myresponse = myrequest.GetResponse()" in the post code - I'm getting following error: "The remote server returned an error: (500) Internal Server Error". I don't know if I have something wrong with the post or receiving it on...
2
1360
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
3885
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 = "test=" + httputility.urlencode(doc.outerxml)' as a http xml post and then need to receive it on other end for a test. It needs to be sent as a stream. I need some sample code on how to post it and then receive the request on
0
8685
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
9032
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...
1
8908
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4374
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
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
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
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.