如何在curl中使用PATCH动词 [英] How to use PATCH verb with curl

查看:1366
本文介绍了如何在curl中使用PATCH动词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对服务器进行PATCH调用。我正在使用以下命令:

I am trying to make a PATCH call to a server. I am using the following command:

curl --data status=closed -X PATCH https://api.viafoura.com/v2/dev.viafoura.com/pages/7000000043515 

这是发送PATCH的正确方法请求?我收到一个错误消息,说没有设置状态参数。我猜测--data仅用于POST请求,因此服务器找不到状态参数。

Is this the correct way of sending the PATCH request? I am getting an error saying there is no status parameter set. I am guessing the --data is for POST request only and thus the server doesn't find the status parameter.

这是响应(FYI):

{"http_status":400,"error":"Parameter validation errors","validation_errors":{"status":{"error":"Request missing status parameter."}}}

您可以找到有关此服务的文档此处

You can find documentation about this service here.

推荐答案

这是您应该使用的格式:

This is the format you should use:

curl --request PATCH https://api.viafoura.com/v2/dev.viafoura.com/pages/7000000043515?status=closed

该API似乎希望 status 参数作为URL上的查询参数,而不是PATCH正文的一部分。

That API seems to want the status parameter as a query parameter on the url, not part of the PATCH body.

指向服务器将返回401错误:必须登录才能修改页面设置。假设您必须先使用类似这样的内容登录:

At this point the server is going to return a 401 error: "You must be logged in to modify page settings." Assumedly you have to login first with something like this:

curl --request POST "https://api.viafoura.com/v2/dev.viafoura.com/users/login?password=TeNn!sNum8er1&email=novak@example.com"

在该示例中,我使用了他们文档中的凭据,我认为该凭据可以在他们的开发服务器上运行,但是当前返回错误密码错误。

I've used the credentials from their documentation in that example, which I figured would work on their dev server, but its currently returning an "Incorrect password" error.

但是,如果您具有有效的凭据,则应获取会话cookie,然后可使用该cookie来验证您的PATCH请求。

If you have valid credentials, though, you should get back a session cookie which you can then use to authenticate your PATCH request.

这篇关于如何在curl中使用PATCH动词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆