简体   繁体   English

如何使用C#捕获HTTP Put请求?

[英]How to capture HTTP Put Requests using C#?

I am trying to create an HTTP PUT request. 我正在尝试创建HTTP PUT请求。 I'm able to send successfully but how do I capture the data being send over ? 我能够成功发送,但是如何捕获正在发送的数据?

When using HTTP Post, the URL being called is triggered, I can capture is using Request.Form, but for HTTP PUT, there seems to be no trigger at all. 当使用HTTP Post时,被调用的URL被触发,我可以使用Request.Form捕获,但是对于HTTP PUT,似乎根本没有触发。

This is a sample code on how do I initiate : 这是有关如何启动的示例代码:

HTTP PUT: HTTP PUT:

var url = "http://localhost:81/index.aspx";<br>
  var client = new HttpClient();
<br>var content = new StringContent("<xml><message>TEST PUT</message></xml>");
         <br>   var response = client.PutAsync(url, content).Result;

What do I do to capture the data in my index.aspx ? 如何捕获index.aspx中的数据?

UPDATE 更新
I created an HTTP handler to accept HTTP requests. 我创建了一个HTTP处理程序来接受HTTP请求。 Calling it http://localhost/RestService/employee 称之为http:// localhost / RestService / employee

Then I use Fiddler to test POST,GET,DELETE and PUT. 然后,我使用Fiddler测试POST,GET,DELETE和PUT。 Three of the method works and invoke my service. 其中三个方法起作用并调用我的服务。 But the PUT method, only returns http 200 from fiddler without invoking my service. 但是PUT方法仅从提琴手返回http 200,而不调用我的服务。 What is so special with PUT that I need to configure? 我需要配置的PUT有何特别之处?

This is my code from RestService 这是我来自RestService的代码

 public void ProcessRequest(HttpContext context)
{
   LogMessage("Service invoked");
   LogMessage("Method used:" + context.Request.HttpMethod);
}

Thanks for your future response. 感谢您日后的回覆。

If I understand you correctly, you want to receive the data that is returned by the webs server, right? 如果我理解正确,那么您想接收Web服务器返回的数据,对吗? In that case, why not use: 在这种情况下,为什么不使用:

if (response.IsSuccessStatusCode) {
    var result = response.Content.ReadAsStringAsync().Result;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM