这是我在此页面上的第一个问题。我在 mvc webapi 和 Windows Store 应用程序中有应用程序,我想用 W8 应用程序向 web api 请求我的对象:
我的对象:
var objobj = new ObjectCompleteAdd()
{
NameObject = "Name",
DescriptionObject = "Description",
isActveObject = true,
ContractStartObject = DateTime.Parse("2005-09-01"),
CityAdress = " CityAdress",
PostCodeAdress = "PostCode",
}
BLL 中的类:
public class ObjectCompleteAdd
{
public string NameObject { get; set; }
public string DescriptionObject { get; set; }
public bool? isActveObject { get; set; }
public DateTime ContractStartObject { get; set; }
public string CityAdress { get; set; }
public string PostCodeAdress { get; set; }
}
和我的功能:
var dataContractSerializer = new DataContractJsonSerializer(typeof(ObjectCompleteAdd));
var memoryStream = new MemoryStream();
dataContractSerializer.WriteObject(memoryStream, objobj);
HttpContent content = new StreamContent(memoryStream);
await client.PostAsync("api/ObjectISApi",content);
在 webapi 我有帖子:
// POST api/ObjectISApi
public HttpResponseMessage PostObjectIS(ObjectCompleteAdd obj)
{
ObjectIS.AddNewObject(obj);
return Request.CreateResponse(HttpStatusCode.OK);
}
它不起作用