开发者

RESTful HTTP DELETE method in .NET

开发者 https://www.devze.com 2022-12-31 03:32 出处:网络
I am new to web services. I am dealing wit开发者_如何学JAVAh testing APIs in my project. In the previous version the company used GET and POST methods but not PUT and DELETE methods. For the HTTP DELE

I am new to web services. I am dealing wit开发者_如何学JAVAh testing APIs in my project. In the previous version the company used GET and POST methods but not PUT and DELETE methods. For the HTTP DELETE method, I have browsed various websites where I found the example code snippets for GET and POST methods, but not for DELETE and PUT methods (why?).

Can anyone give me an example code snippet (C#) for RESTful HTTP DELETE method and explain how to call the DELETE request?


Check out the following code snippet:

string sURL = "<HERE GOES YOUR URL>";

WebRequest request = WebRequest.Create(sURL);
request.Method = "DELETE";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

In the response object you should check the StatusCode property (it should be 200 or 204 if everything goes right, see here for more info).

0

精彩评论

暂无评论...
验证码 换一张
取 消