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 ?
-
Are you using .NET 2.0? Do you see any errors?Joe Ratzer– Joe Ratzer2008-10-11 19:18:11 +00:00Commented Oct 11, 2008 at 19:18
-
You might be best served adding some code to the question.AnthonyWJones– AnthonyWJones2008-10-12 21:11:03 +00:00Commented Oct 12, 2008 at 21:11
-
yes i am using .NET 2.0 no error. but i am not getting any reply content from that. but when i do same with PHP i am getting response content from that.Dr. Rajesh Rolen– Dr. Rajesh Rolen2009-12-28 13:07:08 +00:00Commented Dec 28, 2009 at 13:07
Add a comment
|
3 Answers
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
1 Comment
Dr. Rajesh Rolen
i am implementing it in this way : string targetUri = "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?
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
Comments
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
1 Comment
AnthonyWJones
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.