Как прочитать файл XML на порт 80 с помощью HttpHandler - PullRequest
0 голосов
/ 19 марта 2012

Как мне прочитать XML-файл, отправленный клиентом через порт 80 с помощью HttpHandler в ASP.NET?

1 Ответ

0 голосов
/ 19 марта 2012

предполагается, что клиент использует POST method.

<httpHandler>
  <add path="1.ashx" verb="post" type="" />
</httpHandler>

код Httphandler:

public void ProcessRequest(HttpContext context)
{
    var stream = context.Request.InputStream;
    using (StreamReader sr = new StreamReader(stream))
    {
        var xml= sr.ReadToEnd();  //json format       
        XmlDocument.Load(xml)
    }
}

код клиента с использованием js.

 <script type="text/javascript">
     $.ajax({
        type: 'POST',
        url: "1.ashx",
        data: { xml:"<xml/>" }
    });
</script>
...