在 Postman 中使用 HTTP PATCH 谓词更新数据库 table
Updating database table using HTTP PATCH verb in Postman
我正在开发一个 Azure 移动服务,其中包含一个 table 带有补丁方法的控制器:
public Task<User> PatchUser(string id, Delta<User> patch)
{
return UpdateAsync(id, patch);
}
我在本地托管我的移动服务,想测试 Patch 的工作原理。我正在使用 Postman 来执行此操作,但我不断收到 HTTP 错误 400 和以下响应:
{ "message": "The HTTP request did not include a valid entity body.
Please ensure there is an entity body and an associated Content-Type
header present in the request." }
这些是我附加到 HTTP PATCH 请求的 headers:
这是请求body:
我在 this 网站上看到 POST 请求需要包含这样的正文:[
{ "op": "replace", "path": "/email", "value": "new.email@example.org" }
]
如果我提供您可以在下面的屏幕截图中看到的请求 body,我仍然会得到相同的响应:
这里是 class table 控制器基于的用户:
public class User : EntityData
{
public string Gender { get; set; }
}
我应该如何通过 Postman 正确发送补丁请求?
您应该使用您的第二个请求,但发送 'gender' 属性 小写 g 而不是大写 G.这就是您在模型中定义此 属性 的方式,JSON serializer/deserializer 默认区分大小写。
我正在开发一个 Azure 移动服务,其中包含一个 table 带有补丁方法的控制器:
public Task<User> PatchUser(string id, Delta<User> patch)
{
return UpdateAsync(id, patch);
}
我在本地托管我的移动服务,想测试 Patch 的工作原理。我正在使用 Postman 来执行此操作,但我不断收到 HTTP 错误 400 和以下响应:
{ "message": "The HTTP request did not include a valid entity body. Please ensure there is an entity body and an associated Content-Type header present in the request." }
这些是我附加到 HTTP PATCH 请求的 headers:
这是请求body:
我在 this 网站上看到 POST 请求需要包含这样的正文:[ { "op": "replace", "path": "/email", "value": "new.email@example.org" } ]
如果我提供您可以在下面的屏幕截图中看到的请求 body,我仍然会得到相同的响应:
这里是 class table 控制器基于的用户:
public class User : EntityData
{
public string Gender { get; set; }
}
我应该如何通过 Postman 正确发送补丁请求?
您应该使用您的第二个请求,但发送 'gender' 属性 小写 g 而不是大写 G.这就是您在模型中定义此 属性 的方式,JSON serializer/deserializer 默认区分大小写。