【问题标题】:WCF Make a POST request with a parametersWCF 使用参数发出 POST 请求
【发布时间】:2012-03-28 11:52:22
【问题描述】:

我有一个公开休息端点的 wcf 服务。我想使用提琴手对其进行测试。我有这样的方法:

 [WebInvoke(Method = "POST", UriTemplate = "EditContact", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    string EditContact(string idContact, Contact Contact);

我输入:

POST http://192.168.1.31/ContactLibrary2.0/Service.svc/rest/DeleteContactHTTP/1.1

User-Agent: Fiddler
Host: 192.168.1.31
Content-Type : application/json; Charset=UTF-8

{
"idContact":"67697",
"firstName":"6767",
"lastName":"afdgsg",
"email":"dfghdfdb",
"age":"120",
"street":"sdf",
"city":"dfghgfhjhdfgsdv",
"country":"sdfsd"
}

您可以查看我项目中的更多代码:HERE

我收到 http 400 错误(错误请求错误)。想法?

【问题讨论】:

    标签: json wcf post fiddler


    【解决方案1】:

    您的请求应如下所示:

    POST  http://192.168.1.31/ContactLibrary2.0/Service.svc/rest/DeleteContact HTTP/1.1
    User-Agent: Fiddler
    Content-Type: application/json
    
    {
        "idContact":5,
        "Contact":{
            "idContact":"67697",
            "firstName":"6767",
            "lastName":"afdgsg",
            "email":"dfghdfdb",
            "age":"120",
            "street":"sdf",
            "city":"dfghgfhjhdfgsdv",
            "country":"sdfsd"
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-28
      • 2017-09-13
      • 2015-03-05
      • 2018-10-08
      • 1970-01-01
      • 2017-02-04
      • 2017-06-02
      • 2021-05-18
      • 2014-06-28
      相关资源
      最近更新 更多