我需要设置一个通过 HTTP POST 监听 XML 文档的网页。我不需要发布,我需要接收该 POST。这是什么对象?我应该使用 HTTP 处理程序、Web 服务、webRequest、Stream 还是其他什么?我需要使用 IIS 服务器并且更喜欢 C#。
我试过了...
http://forums.asp.net/t/1371873.aspx/1
如果有人有任何有用的代码或链接,那就太好了!
编辑:
我正在尝试接收来自另一个程序的通知。
最佳答案
您可以编写一个将在 IIS 中托管的 ASP.NET 应用程序,您可以在其中拥有一个 .ASPX 页面或一个通用的 .ASHX handler(取决于您希望如何格式化结果 - 您想返回 HTML 还是其他类型? ) 然后读取包含来自客户端的请求正文的 Request.InputStream
。
下面是一个如何编写通用处理程序 (MyHandler.ashx
) 的示例:
public class MyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
var stream = context.Request.InputStream;
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
string xml = Encoding.UTF8.GetString(buffer);
... do something with the XML
// We only set the HTTP status code to 202 indicating to the
// client that the request has been accepted for processing
// but we leave an empty response body
context.Response.StatusCode = 202;
}
public bool IsReusable
{
get
{
return false;
}
}
}
关于c# - 检索包含 XML 的 HTTP POST 请求,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10049003/