简体   繁体   English

Dynamics CRM Online 和 Web API:通过 POST 的方法隧道

[英]Dynamics CRM Online and Web API : Method Tunneling through POST

I'm using Dynamics CRM 2016 Online and I want to update an entity (a contact for example) using the Web API (odata 4.0) endpoint.我正在使用 Dynamics CRM 2016 Online,我想使用 Web API (odata 4.0) 端点更新实体(例如联系人)。

I use Fiddler to test the request.我使用 Fiddler 来测试请求。 Here are the details of the request :以下是请求的详细信息:

PATCH https://XXXXXXXXXXX/api/data/v8.0/contacts(6b902ae1-19ed-e511-80e3-5065f3890551)
User-Agent: Fiddler
Host: XXXXXXXXX
Content-Length: 54
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json
Authorization: Bearer XXXXXXXX

{
    "firstname": "John",
    "lastname": "Doe"
}

It works well.它运作良好。 The problem is that the client does not support the PATCH verb.问题是客户端不支持 PATCH 动词。

An odata endpoint can handle this limitation by using POST and a additional HTTP header. odata 端点可以通过使用 POST 和额外的 HTTP 标头来处理此限制。 Quote from the documentation :从文档中引用:

In order to help work-around this limitation, OData servers can support method tunneling through POST.为了帮助解决此限制,OData 服务器可以通过 POST 支持方法隧道。 The methods that can be executed through tunneling are MERGE, PUT and DELETE.可以通过隧道执行的方法是 MERGE、PUT 和 DELETE。

To issue a request with method tunneling a client sets up a request with body and headers as needed, but uses POST as the HTTP method instead of the actual required one.要使用方法隧道发出请求,客户端根据需要设置带有正文和标头的请求,但使用 POST 作为 HTTP 方法而不是实际需要的方法。 It then adds one more header, "X-HTTP-Method", and gives it the value MERGE, PUT or DELETE.然后再添加一个标头“X-HTTP-Method”,并赋予它值 MERGE、PUT 或 DELETE。

Servers must check if POST requests have the X-HTTP-Method header set to one of the valid values and if so execute the rest of the request as if the header value was the actual HTTP method for it.服务器必须检查 POST 请求是否将 X-HTTP-Method 标头设置为有效值之一,如果是,则执行请求的其余部分,就好像标头值是它的实际 HTTP 方法一样。

But when I try to execute the same request using POST instead of PATCH and with the additional header, I receive a error :但是当我尝试使用 POST 而不是 PATCH 并使用附加标头执行相同的请求时,我收到一个错误:

message=Unmapped Request found, PathTemplate:~/entityset/key, HttpVerb:POST

I also try the X-HTTP-Method-Override header as described here but same result.我还尝试使用此处描述的 X-HTTP-Method-Override 标头,但结果相同。

Is there a mistake from my side or the endpoint does not support this feature ?我这边有错误还是端点不支持此功能? Thanks.谢谢。

Use PATCH (but you say this one is not being supported).使用 PATCH(但你说不支持这个)。

Use PUT (note with PUT you have to specify the attribute URL/{attribute}, which forces you to make for each attribute a PUT call, not the perfect way but its something)使用 PUT(注意 PUT,您必须指定属性 URL/{attribute},这会强制您为每个属性进行 PUT 调用,这不是完美的方式,而是某种方式)

This worked for me instead of a POST.这对我有用,而不是 POST。

https://msdn.microsoft.com/en-us/library/mt607664.aspx https://msdn.microsoft.com/en-us/library/mt607664.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Dynamics CRM 创建帖子 Web API - Creating Post with Dynamics CRM Web API 计算 Dynamics CRM Online web api (ODATA) 中的所有行 - Counting ALL rows in Dynamics CRM Online web api (ODATA) Dynamics CRM WEB API-从实体参考中选择字段 - Dynamics CRM WEB API- Select field from entity reference 将 MSCRM.SuppressDuplicateDetection 标头添加到 CRM Dynamics Web API 请求会提供 HTTP 412 代码 - Adding MSCRM.SuppressDuplicateDetection header to CRM Dynamics Web API request gives HTTP 412 code Dynamics CRM 365 Web Api使用哪个C#OData客户端库? - Which C# OData Client library to use for Dynamics CRM 365 Web Api? 如何连接到CRM Dynamics Online Odata端点LinqPad? - How to Connect to CRM Dynamics Online Odata endpoint LinqPad? 通过Web服务在Dynamics CRM 2013中更新Money字段的首选方法是什么? - What is the preferred method of updating Money fields in Dynamics CRM 2013 via Web Services? 将API与Dynamics CRM集成的最佳实践/方法 - Best Practices / Approaches for integrating API with Dynamics CRM 通过 API 在 Microsoft Dynamics CRM 中为联系人实体创建注释 - Create annotation to a contact entity in Microsoft Dynamics CRM by API 通过Dynamics Web API更改潜在客户所有者 - Changing lead owner via Dynamics Web API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM