本文介绍了POST到ASP.NET的WebAPI使用Fiddler2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一类车型完全相同的实体我已经在数据库中。我有一个存储过程,发生在参数的新行,并在这又填充我的仓库返回表的所有设置。我能看到GET的结果,类型设置,是在内存中的列表PUT和DELETE。我第一次,即使当我关闭Visual Studio和重新打开并运行该项目,有的时候,名单仍然在它之前的状态注意到。它不会从数据库中重新填充,所以我不知道这是为什么首先......其次,我似乎无法得到POST从提琴手工作不像其他的HTTP动词。我确实看到从提琴手值下code出现,但我得到的错误:无效的URI:URI的格式无法确定。我得到了同样的错误,如果我通过一个ID或没有。

I have a class that models exactly the entity I have in the database. I have a stored procedure that takes in parameters for a new row and returns all the settings in the table which in turn populates my repository. I am able to see the results of GET, PUT and DELETE in the List of type Setting that is in memory. I am noticing first that even when I close Visual Studio and reopen and run the project, sometimes, the List is still in the state it was before. It is not repopulating from the database so I'm not sure why that is first of all... Secondly, I can't seem to get POST to work from Fiddler unlike the other HTTP verbs. I DO see the values from Fiddler show up in the code below but I get the error: Invalid URI: The format of the URI could not be determined. I get the same error if I pass an ID or not.

下面是我投入小提琴手:

Here is what I put into Fiddler:

POST本地主机:54852 / API /设置

请求头

User-Agent: Fiddler
Content-type: application/x-www-form-urlencoded
Host: localhost:54852
Content-Length: 149

请求体

ID=0&Category=Dried%20Goods&Sub_Category=Other&UnitSize=99&UnitOfMeasureID=999&Facings=true&Quantity=true&EverydayPrice=999.99&PromotionPrice=111.11

我SettingsController内PostSetting功能

PostSetting function within my SettingsController

     public HttpResponseMessage PostSetting(Setting item)
    {
        item = repository.Add(item);            
        var response = new HttpResponseMessage<Setting>(item) { StatusCode = HttpStatusCode.Created };
        string uri = Url.Route("DefaultApi", new { id = item.ID });
        response.Headers.Location = new Uri(uri);
        return response;
    }

我应该创建一个从数据库中获取的MAXID一个新的程序,并使用如上面在创建一个新的ID行新的ID?

Should I create a new procedure that gets the MAXID from the database and use that as the NEW ID in the line above where a new ID is created?

推荐答案

您需要创建设置类或项目,你是想与使用Fiddler测试(现在的产品),并使用作曲家标签。

You need to create a JSON representation of the Setting class or item that you are wanting to test with use Fiddler (now a Telerik product) and use the Composer tab.

接下来,您将要执行POST到以下网址:

Next you will want to perform a POST to the following URL:

HTTP:// [你的基地URL] / API /设置

http://[your base url]/api/settings

和通过JSON格式设置类。

and pass the JSON formatted setting class.

您可以看到这个在这里一个例子:

You can see an example of this here: ASP.NET Web API - Scott Hanselman

这篇关于POST到ASP.NET的WebAPI使用Fiddler2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 18:16