尝试使用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()
方法中进行调试,但是 drmObject
是 null
。
感谢您的建议。