简体   繁体   English

如何在restsharp中编写这个cURL?

[英]How to write this cURL in restsharp?

I'm strugling to convert this cURL into restsharp,我正在努力将这个 cURL 转换为 restsharp,

curl https://pwgateway.com/api/token \
-d "public_key=YOUR_PUBLIC_API_KEY" \
-d "card[number]=4000000000000002" \
-d "card[exp_month]=01" \
-d "card[exp_year]=2021" \
-d "card[cvv]=123"

Ive tried like this:我试过这样:

ServicePointManager.SecurityProtocol |= SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var client = new RestClient("https://api.paymentwall.com/api/brick/token");
var request = new RestRequest(Method.POST);

request.AddParameter("X-ApiKey", "privatekey",ParameterType.HttpHeader);
request.AddParameter("public_key", "publickey", ParameterType.HttpHeader);
request.AddParameter("card[number]", "4000000000000002", ParameterType.HttpHeader);
request.AddParameter("card[exp_month]", "01", ParameterType.HttpHeader);
request.AddParameter("card[exp_year]", "21", ParameterType.HttpHeader);
request.AddParameter("cardcard[cvv]", "123", ParameterType.HttpHeader);

I get empty string,also tried removing ParameterType.HttpHeader from data parameters public_key,card[number] etc, then I get error missing parameters.我得到空字符串,还尝试从数据参数 public_key、c​​ard[number] 等中删除 ParameterType.HttpHeader,然后我得到错误缺少参数。

Documentation is on this link文档在此链接上

Documentation 文档

After few tests and playing around, this seems to be working经过几次测试和玩耍后,这似乎有效

contentList.Add("card[cvv]=123");
            contentList.Add("card[exp_year]=2021");
            contentList.Add("card[exp_month]=01");
            contentList.Add("card[number]=4000000000000002");
            contentList.Add("public_key=mykey");
            var body = string.Join("&", contentList);

            request.AddParameter("application/x-www-form-urlencoded", body, ParameterType.RequestBody);

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

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