如何在Fiddler中创建一个Post请求

6
尝试使用Fiddler发送Post请求到我的C# API,如下所示(这是在VS2012中进行的开发环境)。但是,在C#中我的请求对象为null。在composer选项卡的解析选项卡中,我的post URL为:http://localhost:33218/api/drm。
User-Agent: Fiddler/4.4.9.2 (.NET 4.0.30319.34209; WinNT 6.1.7601 SP1; en-US; 4xAMD64)
Pragma: no-cache
Accept-Language: en-US
Host: localhost:33218
Accept-Encoding: gzip, deflate
Connection: Close
Content-Length: 80

请求正文:

&sid=f7f026d60bb8b51&riskMeasureName=RMTest

以下是C# API方法:

// POST api/drm 
public HttpResponseMessage Post([FromBody]JObject drmObject)
{
     string sid = drmObject.GetValue("sid").ToString();
     string riskMeasCategory = drmObject.GetValue("riskMeasureName").ToString();
     string response = DynAggrClientAPI.insertDRMCategory(sid, riskMeasCategory);

     var httpResp = Request.CreateResponse(HttpStatusCode.OK);
     httpResp.Content = new StringContent(response, Encoding.UTF8, "application/json");

     return httpResp;
}

我可以在我的C# Post() 方法中进行调试,但是 drmObjectnull

感谢您的建议。

1个回答

8

您没有发送content-type,因此MVC无法确定如何解释数据。

您的数据似乎类似于表单POST,请添加标题:

Content-Type: application/x-www-form-urlencoded

哇,我一定已经删除了它。在添加“Content-Type”后,它肯定有效!@CodeCaster - bob.mazzo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接