我用 c# wcf 服务编写的代码。调用第三方支付API。
string requestBody = "{ \"cardToken\":\"xxxxx\", \"expiryDate\":\"xxxx\",\"cvv\":\"xxx\",\"amount\":\"xxx\" }";
string data = Newtonsoft.Json.JsonConvert.SerializeObject(requestBody);
var content = new StringContent(data, Encoding.UTF8, "application/json");
HttpResponseMessage responseDebitAPI = client.PostAsync("http://example.com/example/api/payments/debit?access_token=xxxxxxxxxxxxxx", content).Result;
调用 API 后,我收到以下错误:
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Date: Tue, 20 Jun 2017 08:04:59 GMT
Server: Microsoft-IIS/8.0
X-Powered-By: ASP.NET
Content-Length: 1011
Content-Language: en
Content-Type: text/html; charset=utf-8
}}
如果我做错了,请在上面的代码中帮助我。
请试试这个,让我知道结果:
string requestBody = "{ \"cardToken\":\"xxxxx\", \"expiryDate\":\"xxxx\",\"cvv\":\"xxx\",\"amount\":\"xxx\" }";
string data = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(requestBody);
var content = new StringContent(data, Encoding.UTF8, "application/json");
HttpResponseMessage responseDebitAPI = client.PostAsync("http://example.com/example/api/payments/debit?access_token=xxxxxxxxxxxxxx", content).Result;
您正在将输入序列化三遍!!那就是问题所在。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句