如何将curl请求转换为HttpClient

时间:2017-04-12 15:32:22

标签: c# .net curl dotnet-httpclient asynchttpclient

我有一个卷曲请求,如下所示:

curl -i -XPOST 'http://my_url:port/write?db=myDb' -u user:xxxxx --data-binary 'FieldName,host=M.233 value=52.666 timestamp'

我试图使用HttpClient发布此请求。我不确定我应该怎么称呼它。这就是我试图做的事情:

public async void  TestHttpClient()
{ 
    var client = new HttpClient();
    var credentials = Encoding.ASCII.GetBytes("user:xxxxx");
    var header = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials));
    client.DefaultRequestHeaders.Authorization = header;
    client.BaseAddress = new Uri("http://my_url:port/write?db=myDb");
    var result = await client.PostAsync(..);
}

我应该为PostAsync()编写哪些参数?

如何将--data-binaryFieldName,host=M.233 value=52.666 timestamp从curl转换为HttpClient?

1 个答案:

答案 0 :(得分:2)

我的解决方案是:

swagger-maven-plugin