1

我有一些 JSON 示例,我想发布到我的 WebAPI 进行测试,但我看不到它可以对我传入的对象进行反序列化。

这是我的表格:

<form  action="/api/orders" method="post" >
              <textarea type="text" id="order" name="order"></textarea>
              <input type="submit"/>
</form>

这是我的方法:

 [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"
} 

我认为这可能是因为内容类型不是application/json来自表单。

我怎样才能简单地测试它并让它工作?

4

1 回答 1

1

尝试使用jQuery.post函数。也看看这个答案

于 2013-03-12T16:10:47.743 回答