使用 restsharp 删除函数 Irestreponse
Delete function Irestreponse with restsharp
我想用 Restful API 和 RestSharp 实现删除功能。我已经实现了 GET 和 POST 功能。但是有了这个删除功能,我没有从 API 得到任何反馈,只有一个 httpresponse。我的问题是如何编写代码以便执行删除功能?我已经有了这个:
// var url = string.Format("url");
// Construct the request.
// var request = new RestRequest(url, Method.DELETE);
// //IRestResponse<> response;
// //response = await restClient.ExecuteTaskAsync<>(request);
// //return response.Data;
试一试
var client = new RestClient(url);
var request = new RestRequest(Method.DELETE);
IRestResponse response = client.Execute(request);
这里的重点是在 header 中包含代码中显示的值的“接受”。
string url = "http://localhost:8080/laptop-bag/webapi/api/delete/2";
IRestRequest restRequest = new RestRequest(url);
restRequest.AddHeader("Accept", "*/*"); //Important
IRestClient restClient = new RestClient();
IRestResponse restResponse = restClient.Delete(restRequest);
//Status code will be 200 for successful execution
int statusCode = Convert.ToInt32(restResponse.StatusCode);
我想用 Restful API 和 RestSharp 实现删除功能。我已经实现了 GET 和 POST 功能。但是有了这个删除功能,我没有从 API 得到任何反馈,只有一个 httpresponse。我的问题是如何编写代码以便执行删除功能?我已经有了这个:
// var url = string.Format("url");
// Construct the request.
// var request = new RestRequest(url, Method.DELETE);
// //IRestResponse<> response;
// //response = await restClient.ExecuteTaskAsync<>(request);
// //return response.Data;
试一试
var client = new RestClient(url);
var request = new RestRequest(Method.DELETE);
IRestResponse response = client.Execute(request);
这里的重点是在 header 中包含代码中显示的值的“接受”。
string url = "http://localhost:8080/laptop-bag/webapi/api/delete/2";
IRestRequest restRequest = new RestRequest(url);
restRequest.AddHeader("Accept", "*/*"); //Important
IRestClient restClient = new RestClient();
IRestResponse restResponse = restClient.Delete(restRequest);
//Status code will be 200 for successful execution
int statusCode = Convert.ToInt32(restResponse.StatusCode);