简体   繁体   English

我将如何在C#中提出这个curl请求?

[英]How would I make this curl request in C#?

This the the curl request I need to make in C#: 这是我需要在C#中进行的curl请求:

curl -X PURGE http://www.example.com/image.jpg

It is the PURGE part that is throwing me off, I was going to do this in RestSharp but WebClient or whatever will work just fine as well. 是PURGE部分使我无法接受,我打算在RestSharp中执行此操作,但是WebClient或其他任何方法也可以正常工作。

I find HttpClient to be a convenient way to send requests these days. 我发现HttpClientHttpClient发送请求的便捷方法。 The key is to recognize that you can create a custom HttpMethod by passing a string to its constructor. 关键是要认识到可以通过将字符串传递给其构造函数来创建自定义HttpMethod

using (var client = new HttpClient())
using (var request = new HttpRequestMessage(
    new HttpMethod("PURGE"), 
    new Uri("http://www.example.com/image.jpg")))
using (var response = await client.SendAsync(request))
{
    // work with response
}

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

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