简体   繁体   English

如何在C#中使用REST,包括PUT,POST和DELETE?

[英]How to consume REST in C# including PUT, POST and DELETE?

I have a REST webservice that I need to consume in C#. 我有一个我需要在C#中使用的REST Web服务。 I need support for more than just GET requests though. 我需要支持的不仅仅是GET请求。 I need everything that is done by REST including GET, PUT, POST, and DELETE. 我需要REST完成的所有工作,包括GET,PUT,POST和DELETE。 What is the best way of interfacing with this? 与此接口的最佳方式是什么? I do not see anything for HTTPRequest to be able to do POST or anything other than GET unless you construct your own headers(which I prefer not to) 我没有看到任何HTTPRequest能够进行POST或GET以外的任何事情,除非你构建自己的头文件(我不喜欢)

Is there some easy and lightweight way to fully consume REST webservices in C#? 是否有一些简单轻量的方法可以在C#中完全使用REST Web服务?

Check out the series of screencasts on WCF REST up on Channel 9: 在Channel 9上查看WCF REST上的一系列截屏视频:

http://channel9.msdn.com/tags/REST%20Starter%20Kit%20endpoint%20screencasts/ http://channel9.msdn.com/tags/REST%20Starter%20Kit%20endpoint%20screencasts/

There's a great one amongst those called Consuming REST services with HttpClient which should give you a nice step-by-step instruction on how to do all of this. 在那些名为Consuming REST服务的HttpClient中有一个很棒的它应该给你一个关于如何做所有这些的一个很好的分步指导。

Also check out the WCF REST Developer Center on MSDN for more articles, blog posts, and tutorial on WCF and REST. 另请参阅MSDN上的WCF REST开发人员中心 ,以获取有关WCF和REST的更多文章,博客文章和教程。

The HttpClient in the Microsoft.Http namespace that comes with the WCF Rest Starter kit is very helpful. WCF Rest Starter工具包附带的Microsoft.Http命名空间中的HttpClient非常有用。

Aaron Skonnard from Pluralsight created several articles and screencasts highlighting the HttpClient. Pluralsight的Aaron Skonnard创作了几篇强调HttpClient的文章和截屏视频。

There are several more resources that he posted to the Pluralsight blog in March 2009 covering the HttpClient. 在2009年3月Pluralsight博客发布了更多资源,涵盖了HttpClient。

您可以查看CodePlex上的REST Starter Kit

HTTPRequest is the request currently processed in a ASP app. HTTPRequest是当前在ASP应用程序中处理的请求。

To make outboud HTTP REST requests, use the HttpWebRequest class. 要发出远程HTTP REST请求,请使用HttpWebRequest类。 It has properties like Method (POST, PUT, DELETE) and you can write your payload into the request stream returned by GetRequestStream (or its async counterpart for high performance). 它具有像Method (POST,PUT,DELETE)这样的属性,您可以将有效负载写入GetRequestStream (或其异步对应项以获得高性能)返回的请求流中。

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

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