I want to post an xml document to an asp page from an asp.net page. If I use WebRequest with content/type text/xml the document never gets to the asp page. How can I do this ?
A:
It's absolutely possible. Make sure that you are writing the XML to the RequestStream.
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getrequeststream.aspx
Darren Kopp
2008-10-11 19:20:58
A:
I do use GetRequestStream. But if you try to send xml like <data id='10'>value</data>
with content-type text/xml the document never gets to its destination
It is difficult to know how you are determining that the document never makes it to the destination. Does the code in the ASP actually run? How are you consuming the Request entity? Show us some code! Please don't post another answer this is not an NG or forum. Edit your original question.
AnthonyWJones
2008-10-14 15:13:05
A:
Maybe instead of sending the whole document, you could write a temporary file and then pass the location of that temp file to the ASP page.
AnonJr
2008-11-23 16:01:55
+2
A:
Here is a sample without any error handling (do it yourself :) ):
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetUri);
string sendString = formParameterName + "=" + HttpUtility.UrlEncode(xmlData);
byte[] byteStream;
byteStream = System.Text.Encoding.UTF8.GetBytes(sendString);
request.Method = POST;
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteStream.LongLength;
using(Stream writer = request.GetRequestStream())
{
writer.Write(byteStream, 0, (int)request.ContentLength);
writer.Flush();
}
HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
//read the response
Sunny
2008-11-24 20:55:19
i am implementing it in this way :string targetUri = "http://www.hostelspoint.com/xml/xml.php"; System.Xml.XmlDocument reqDoc = new System.Xml.XmlDocument(); reqDoc.Load(Server.MapPath("~\\myfile.xml")); string xmlData = reqDoc.InnerXml; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetUri); string sendString = formParameterName + "=" + HttpUtility.UrlEncode(xmlData);what will "formParameterName" contain?
Rajesh Rolen- DotNet Developer
2009-12-28 13:03:50