[英]How to write this cURL in 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"
我試過這樣:
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);
我得到空字符串,還嘗試從數據參數 public_key、card[number] 等中刪除 ParameterType.HttpHeader,然后我得到錯誤缺少參數。
文檔在此鏈接上
經過幾次測試和玩耍后,這似乎有效
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.