【问题标题】:Response error in wcf c# APIwcf c# API中的响应错误
【发布时间】:2017-06-20 10:14:10
【问题描述】:

我的代码是用 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
}}

如果我做错了,请在上面的代码中帮助我。

【问题讨论】:

    标签: c# asp.net wcf


    【解决方案1】:

    请试试这个并告诉我结果:

    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;
    

    您正在序列化输入 3 次!!这就是问题所在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-11
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2019-10-18
      • 2012-05-22
      • 2015-10-25
      相关资源
      最近更新 更多