How to send xml to asp page using webrequest from asp.net?

I want to publish an XML document on an asp page on an asp.net page . If I use WebRequest with text content / type / xml, the document never gets to the asp page. How can i do this?

+3
source share
3 answers

Here is an example without 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
+2
source

It is absolutely possible. Make sure you write XML in RequestStream.

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getrequeststream.aspx

0
source

GetRequestStream. xml <data id='10'>value</data> /xml ,

0

Source: https://habr.com/ru/post/1698172/


All Articles