0

Odata 对我来说是一个新事物,我正在尝试深入了解它。所以我正在尝试使用 OData 协议以原子格式插入数据并使用休息客户端。所以我创建了以下 http Post 请求:

POST /HelloOdata/library.xsodata/books HTTP/1.1
Host: coe-he-55:8010
Authorization: Basic xxxxxxxxxxxxxxxxxxxxx
DataServiceVersion: 1.0
MaxDataServiceVersion: 2.0
accept: application/atom+xml
Content-Type: application/atom+xml
Cache-Control: no-cache
Postman-Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

<?xml version="1.0" encoding="utf-8"?> 
<Entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
    xmlns="http://www.w3.org/2005/Atom">
  <title type="text">books</title> 
  <author> 
    <name /> 
  </author>
        <link href="books('Test_post')/Author" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Author" title="Author" type="application/atom+xml;type=entry"/>
  <category term="HelloOdata.library.booksType"
      scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
  <content type="application/xml"> 
    <m:properties> 
      <d:title>Test_post</d:title>
      <d:ISBN>ISBN_POST</d:ISBN>
      <d:editions>2</d:editions>
    </m:properties> 
  </content> 
</Entry>

作为回应,我得到了:序列化资源缺少成员“标题”的值。

好吧,我的表书只有三个属性,即标题、ISBN 和版本,正是我试图通过此语句插入的那些。那么,您知道其中有什么问题吗?

谢谢巴勃罗

4

1 回答 1

0

我找到了错误在哪里。令人难以置信的是正确的 xml 请求是:

POST /HelloOdata/library.xsodata/books HTTP/1.1
Host: coe-he-55:8010
Authorization: Basic xxxxxxxxxxxxxxxxxxxxx
DataServiceVersion: 1.0
MaxDataServiceVersion: 2.0
accept: application/atom+xml
Content-Type: application/atom+xml
Cache-Control: no-cache
Postman-Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

<?xml version="1.0" encoding="utf-8"?> 
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
    xmlns="http://www.w3.org/2005/Atom">
  <title type="text">books</title> 
  <author> 
    <name /> 
  </author>
  <category term="HelloOdata.library.booksType"
      scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
  <content type="application/xml"> 
    <m:properties> 
      <d:title>Test_post</d:title>
      <d:ISBN>ISBN_POST</d:ISBN>
      <d:editions>2</d:editions>
    </m:properties> 
  </content> 
</entry>

好吧,我也不得不离开这部分:

 <link href="books('Test_post')/Author" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Author" title="Author" type="application/atom+xml;type=entry"/>

但这是第一次之后的尝试,因为真正的问题是标签

<Entry> 

用 E 写而不是

<entry>

一旦我更改了它,Http 请求就可以正常工作。

我在官方网站指南上看到了这个使用 OData 插入数据的示例: http ://www.odata.org/documentation/odata-version-2-0/operations并且标签条目是用大写字母写的。

谢谢!巴勃罗

于 2014-07-11T12:38:55.483 回答