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

Sending XML via HttpWebRequest

Hello,

I want to send a XML message (string) to an ASP.net page,
I don't want to use WebService because the ASP.net page
has been developed by an external company, can you please
point me to the correct location for examples on how to
send XML messages to an ASP.net page using C#.

Thanks,
Nov 18 '05 #1
5 1986
you want to send xml to aspx page but you do not want to use webservice.
Well in anycase if you want to post the data to a webpage you need to use
either QueryString or Form.
With XML i am afraid it can get pretty long and you could run out of max
querystring length.
in that case just htmlencode the xml and pass it as a form param.
Though to post to another aspx page (if you are using aspx as well) you will
have to rely on html form rather than server side form (so remove
runat=server from form in html view of designer)

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"BuddyWork" <an*******@discussions.microsoft.com> wrote in message
news:36****************************@phx.gbl...
Hello,

I want to send a XML message (string) to an ASP.net page,
I don't want to use WebService because the ASP.net page
has been developed by an external company, can you please
point me to the correct location for examples on how to
send XML messages to an ASP.net page using C#.

Thanks,

Nov 18 '05 #2
I think something like this might work for you:
/// <summary>
/// Sends an xml document over http, and returns the xml server response
/// </summary
public XmlDocument SubmitDocument(XmlDocument xDoc, string URL)
{
try
{
// get the data from the xml document into a byte stream
Byte[] bdata = System.Text.Encoding.ASCII.GetBytes(xDoc.OuterXml) ;
// instantiate a web client
System.Net.WebClient wc = new System.Net.WebClient();
Byte[] bresp;
// add appropriate headers
wc.Headers.Add("Content-Type","text/xml");
// send data to server, and wait for a response
bresp = wc.UploadData(URL, bdata);
// read the response
string resp = System.Text.Encoding.ASCII.GetString(bresp);
XmlDocument xresp = new XmlDocument();
xresp.LoadXml(resp);
// return the xml document response from the server
return xresp;
}
catch
{
// your error handler
SystemError();
}

}
"BuddyWork" <an*******@discussions.microsoft.com> wrote in message
news:36****************************@phx.gbl...
Hello,

I want to send a XML message (string) to an ASP.net page,
I don't want to use WebService because the ASP.net page
has been developed by an external company, can you please
point me to the correct location for examples on how to
send XML messages to an ASP.net page using C#.

Thanks,

Nov 18 '05 #3
Craig wrote:
I think something like this might work for you:
/// <summary>
/// Sends an xml document over http, and returns the xml server
response /// </summary
public XmlDocument SubmitDocument(XmlDocument xDoc, string URL)
{
try
{
// get the data from the xml document into a byte stream
Byte[] bdata = System.Text.Encoding.ASCII.GetBytes(xDoc.OuterXml) ;
// instantiate a web client
System.Net.WebClient wc = new System.Net.WebClient();
Byte[] bresp;
// add appropriate headers
wc.Headers.Add("Content-Type","text/xml");
// send data to server, and wait for a response
bresp = wc.UploadData(URL, bdata);
// read the response
string resp = System.Text.Encoding.ASCII.GetString(bresp);
XmlDocument xresp = new XmlDocument();
xresp.LoadXml(resp);
// return the xml document response from the server
return xresp;
}
catch
{
// your error handler
SystemError();
}

}


Just a note: Don't use ACSII encoding with XML. Use the specific encoding
your XML documents use, or UTF-8 as fallback. No non-7 bit character will
survive this torture otherwise ;-)

Cheers,

--
Joerg Jooss
jo*********@gmx.net
Nov 18 '05 #4

"Joerg Jooss" <jo*********@gmx.net> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
Just a note: Don't use ACSII encoding with XML. Use the specific encoding
your XML documents use, or UTF-8 as fallback. No non-7 bit character will
survive this torture otherwise ;-)

Cheers,

--
Joerg Jooss
jo*********@gmx.net


You are, of course, correct, and thank you for pointing out my error.
That's what I get for throwing something together in a hurry.

Cheers,
Craig
Nov 18 '05 #5
Craig wrote:
"Joerg Jooss" <jo*********@gmx.net> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
Just a note: Don't use ACSII encoding with XML. Use the specific
encoding your XML documents use, or UTF-8 as fallback. No non-7 bit
character will survive this torture otherwise ;-)

Cheers,

--
Joerg Jooss
jo*********@gmx.net


You are, of course, correct, and thank you for pointing out my error.
That's what I get for throwing something together in a hurry.


Never mind. Unfortunately, there are quite a few code samples on the web
employing this dangerous practice :-S

Cheers,

--
Joerg Jooss
jo*********@gmx.net
Nov 18 '05 #6

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

Similar topics

2
by: Carl Gilbert | last post by:
Hello! How can I make a web request without getting the url encoded. I want to make a request to a web server that takes "\" as part of the url but can't handle "%5C" which would be the url...
5
by: PerryG | last post by:
We have a .NET 1.1 client which is sending a gzipped soap request using HttpWebRequest to an Apache server. The Apache server is using a the 'mod_deflate' server to decompress the incoming...
4
by: Mark | last post by:
i have a very simple web servive Imports System.Web.Services <System.Web.Services.WebService(Namespace:="urn:Example1")> _ Public Class Example1 Inherits System.Web.Services.WebService
9
by: Michael Evanchik | last post by:
Hello all, since i wanted to use ssl and its seems easy to do so with this object. Im trying to login to a webserver (aol) for this example. But for some reason, im packet sniffing with ethreal...
2
by: Andres | last post by:
I am creating a web request (HttpWebRequest) from a web page in order to retrieve the Html from another page and embed it in the calling page. When you create a HttpWebRequest the request is...
0
by: Kevin | last post by:
I am successfully creating and deleting appointments and sending invitations in a C# / ASP.NET / Exchange2000 environment. It works great! But the problem is that no notifications are sent out...
1
by: Marvin | last post by:
my asp.net app is posting to another webpage using httpwebRequest & x509Certificates and in return the certificate's name used for the posting is sent back. But instead of getting information about...
4
by: Christina N | last post by:
What is the easiest way to make an ASP.Net application send data to another web-app? For instance I would like APP3 to log user stats from APP1 and APP2. The applications are located on different...
6
by: Rushwire | last post by:
Does anybody know how to send a meeting request using an ics/vcs (VCalendar) attachment from an asp.net page. I don't want my users to have to double click on the attachment but rather that it is...
0
by: sanjaygupta11 | last post by:
I am using httpwebrequest and httpwebresponse objects for sending data to remote appication by post and receiving the response from there. I am using this code in my windows application which 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: 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: 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
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,...
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
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...
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...

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.