CURL 发布请求到 C# 发布请求

你能帮我在c#中提出一个post请求吗?这是卷曲:


curl -X POST https://api.test.com/call \

  -H "Content-Type: application/json" \

  -H "Authorization: Token token=YOUR_TOKEN" \

  -d '{"amount":10.00, "id":"123", "customer":{"external_id":"100"}, "receiver":{"external_id":"200"}}'

我尝试这样做:


string myJson = "{"amount":10.00, "id":"123", "customer":{"external_id":"100"}, "receiver":{"external_id":"200"}}";

    using (var client = new HttpClient())

                {

                    client.BaseAddress = new Uri("https://api.test.com");                    

                    client.DefaultRequestHeaders.Add("APIAccessToken", "myToken");               

                    var content = new StringContent(myJson, Encoding.UTF8, "application/json");

                    var response = await client.PostAsync("https://api.test.com/call/", content);

                    resultContent = await response.Content.ReadAsStringAsync();

                }

但是收到错误的请求响应 400 错误。我是新手,将感谢您的帮助。


呼啦一阵风
浏览 225回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP