Model always null on XML POST

前端 未结 5 1267
耶瑟儿~
耶瑟儿~ 2020-11-30 22:36

I\'m currently working on an integration between systems and I\'ve decided to use WebApi for it, but I\'m running into an issue...

Let\'s say I have a model:

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 23:09

    Two things:

    1. You don't need quotes "" around the content type and accept header values in Fiddler:

      User-Agent: Fiddler
      Content-Type: application/xml
      Accept: application/xml
      
    2. Web API uses the DataContractSerializer by default for xml serialization. So you need to include your type's namespace in your xml:

       
          Sito
       
      

      Or you can configure Web API to use XmlSerializer in your WebApiConfig.Register:

      config.Formatters.XmlFormatter.UseXmlSerializer = true;
      

      Then you don't need the namespace in your XML data:

       Sito
      

提交回复
热议问题