C# 4.0 使用JSON从表单测试WebAPI中的帖子
我有一些JSON示例,我想发布到我的WebAPI fo测试中,但我看不到如何让它对我传递的对象进行反序列化 这是我的表格:C# 4.0 使用JSON从表单测试WebAPI中的帖子,c#-4.0,asp.net-web-api,C# 4.0,Asp.net Web Api,我有一些JSON示例,我想发布到我的WebAPI fo测试中,但我看不到如何让它对我传递的对象进行反序列化 这是我的表格: <form action="/api/orders" method="post" > <textarea type="text" id="order" name="order"></textarea> <input type="submit"/> </form&g
<form action="/api/orders" method="post" >
<textarea type="text" id="order" name="order"></textarea>
<input type="submit"/>
</form>
我认为这可能是因为内容类型不是来自表单的application/json
如何简单地测试并使其工作?尝试使用函数。另请看一下尝试使用函数。另请看一下您的类
顺序如何
?简单类,在上面添加了一些示例数据您的类顺序如何
?简单类,在上面添加了一些示例数据是的,JQuery将是一个很好的选择。web浏览器使用表单url编码提交表单。是的,JQuery是一个不错的选择。web浏览器使用表单url编码提交表单。
[HttpPost]
public HttpResponseMessage Post(Model.Order order)
{
var response = Request.CreateResponse<Order>(HttpStatusCode.Created, order);
string uri = Url.Link("DefaultApi", new { id = order.OrderID });
response.Headers.Location = new Uri(uri);
return response;
}
{
"ShipToContactPhone" : "9999999999",
"ContactPhone" : "9999999999",
"IsPlaced" : 0,
"ContainerName" : null,
"Terms" : "3",
"ShipDate" : null,
"OrderGUID" : "6D55FB6E-36A2-43F3-8316-2BE740ACC8E1",
"CatalogName" : null,
"ShipToCountry" : "USA",
"SalesRepID" : 0,
"OrderType" : null,
"ShipVia" : null,
"IsContainer" : null,
"BillingAddress1" : "TEST ACCOUNT",
"BillingCity" : "BROOK",
"CustomerID" : 721182,
"BillingAddress2" : "",
"OrderStatus" : "Accept",
"TaxTotal" : 0,
"Source" : null,
"Discount" : 0,
"OrderDate" : "3\/8\/13",
"CustomerNumber" : "26",
"OrderTotal" : 2160,
"ShippingTotal" : 0,
"ShipToZip" : "07663",
"CurrencyCode" : "USD",
"TaxRate" : 0,
"Origin" : null,
"CancelDate" : null,
"WrittenByName" : "(null)",
"BillingState" : "NJ",
"Exported" : null,
"ShipToAddress1" : "6 ANYWHERE STREET",
"ShipToAddress2" : "",
"Notes" : "",
"FreightTerm" : null,
"ShipToContactEmail" : "test@test.com",
"ContactEmail" : "test@test.com",
"ShipToFax" : "9999999999",
"ContactName" : "",
"PONumber" : "",
"ShipToContactName" : null,
"WrittenForName" : null,
"CatalogCode" : null,
"ManufacturerID" : 3456,
"ShipToCompanyName" : "TEST",
"ShipToState" : "NJ",
"isDefault" : 1,
"PriceLevel" : 5,
"ShipToCity" : "BROOK",
"ContainerCubes" : 0,
"WrittenForRepnumber" : null,
"MarketName" : "",
"DoNotShipBefore" : null,
"RepNumber" : null,
"FOB" : null,
"IsDeleted" : null,
"SubTotal" : 0,
"ContactFax" : "9999999999",
"BillingZip" : "07663",
"CustomerName" : "TEST",
"ExportDate" : null,
"OrderID" : 0,
"WrittenForRepNumber" : null,
"BillingCountry" : "USA"
}