简体   繁体   English

怎么把curl“ --user”命令转换成Restsharp?

[英]How to convert curl “--user” command to Restsharp?

My curl is 我的卷发是

curl -X POST -d "email=jeff@example.com" -d "password=*******" 
         --user admin@example.com:password https://example.com/admin/web/users/add

what I have so far is 我到目前为止所拥有的是

var client = new RestClient("https://example/admin/web/users/add");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddHeader("accept", "application/json");
request.AddParameter("application/x-www-form-urlencoded", "email=jeff@example.com" + "password=********", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Console.WriteLine(response.Content);

what i dont understand is where do I put 我不明白的是我放在哪里

--user admin@example.com:password

Unless specified otherwise, curl uses HTTP Basic authentication when making HTTP(S) requests. 除非另有说明,否则curl在发出HTTP(S)请求时会使用HTTP基本身份验证。

In RestSharp, HTTP Basic auth is provided via the RestSharp.Authenticators.HttpBasicAuthenticator type: 在RestSharp中,通过RestSharp.Authenticators.HttpBasicAuthenticator类型提供HTTP基本身份验证:

var client = new RestClient("https://example/admin/web/users/add");
client.Authenticator = new HttpBasicAuthenticator("admin@example.com", "password");
...

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

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