【问题标题】:How to create a Post request in Fiddler如何在 Fiddler 中创建 Post 请求
【发布时间】:2015-03-19 20:56:14
【问题描述】:

尝试如下向我的 C# API 发送 Fiddler Post 请求(这是我使用 VS2012 的开发环境)。但是,我的请求对象是 C# 中的null。在作曲家选项卡的已解析选项卡中。我的帖子地址: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

感谢您的建议。

【问题讨论】:

    标签: http-post fiddler


    【解决方案1】:

    您没有发送内容类型,因此 MVC 无法判断如何解释数据。

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

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

    【讨论】:

    • 哇,我一定把它删了。这肯定在添加 Content-Type 时起作用! @CodeCaster
    猜你喜欢
    • 1970-01-01
    • 2022-09-28
    • 1970-01-01
    • 1970-01-01
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    相关资源
    最近更新 更多