我有批量请求来更新数据。 数据是:
Item : {
id : int,
name : string,
RefItem : {
int : id,
name : string }
}
我需要
根据OData规范:
--batch_1872-f36a-7ce8
Content-Type: multipart/mixed; boundary=changeset_8c16-9ba3-2260
--changeset_8c16-9ba3-2260
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT $1/$links/ItemRef HTTP/1.1
Content-ID: 2
Accept: application/atomsvc+xml;q=0.8, application/json;q=0.5, /;q=0.1
DataServiceVersion: 1.0
Content-Type: application/json
{"uri":"ItemRefs(1)"}
--changeset_8c16-9ba3-2260
Content-Type: application/http
Content-Transfer-Encoding: binary
POST Products HTTP/1.1
Content-ID: 1
Accept: application/atomsvc+xml;q=0.8, application/json;q=0.5, /;q=0.1
DataServiceVersion: 1.0
Content-Type: application/json
{"id":-1,"name":"seven"}
--changeset_8c16-9ba3-2260--
--batch_1872-f36a-7ce8--
我认为它应该可行,但我有回复错误:
--batchresponse_4febeba8-dd43-4040-9fdb-866afde5304e
Content-Type: multipart/mixed; boundary=changesetresponse_424dbf12-fa9a-4a59-8284-963fa0fa7b77
--changesetresponse_424dbf12-fa9a-4a59-8284-963fa0fa7b77
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 500 Internal Server Error
Content-ID: 2
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
Content-Type: application/json;charset=utf-8
{"d":{"error":{"code":"","message":{"lang":"ru-RU","value":"An error occurred while processing this request."}}}}
--changesetresponse_424dbf12-fa9a-4a59-...
有人可以告诉我哪里错了吗? 感谢。
答案 0 :(得分:0)
批处理请求作为流处理。因此,您只能引用已经看过的内容ID。上述示例在具有该内容ID的请求操作之前引用内容ID 1。这是无效的。
您需要先创建新实例(POST),然后通过$ links URL添加对它的引用。