如何在c#中使用post将json值传递给API

本文关键字:json 值传 API post | 更新日期: 2023-09-27 17:50:20

我是c#新手,你能告诉我在c#中使用POST将json值传递给API的最佳方法吗?

下面我写了python代码,但不确定如何在c#中实现。

string payload = {
   "username" : "1432143352759a61bca0ad4a35a4f0", # when you register, they'll return this
   "password" : "password",
   "client_id" : "c3ca1565b0dbedd74c5c",
   "client_secret" : "e0591fe41c4e2585b313ad93e2748022db3186d0",
}
res = requests.post("https://sandbox.synapsepay.com/api/v2/user/login", payload)
print res.status_code
print res.text

如何在c#中使用post将json值传递给API

在。net客户端(例如WinForm)中,您可以使用HttpClient。

查看这个解决方案:
http://www.asp.net/web-api/overview/advanced/calling-a-web-api-from-a-net-client