ruby - Typhoeus Ruby 删除请求中的有效负载
问题描述
我正在尝试使用 Typhoeus Delete 调用发送请求有效负载(如在 post call 中)。据我所知,HTTP 1.1 规范 (RFC 7231) 的最新更新明确允许在 DELETE 请求中使用实体主体:
A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing implementations to reject the request.
我尝试了此代码,但无法检索正文/有效负载
query_body = {:bodyHash => body}
request = Typhoeus::Request.new(
url,
body: JSON.dump(query_body),
method: :delete,
ssl_verifypeer: false,
ssl_verifyhost: 0,
verbose: true,
)
request.run
response = request.response
http_status = response.code
response.total_time
response.headers
result = JSON.parse(response.body)
另一方面,它以编码方式出现,我无法检索它
另一边的代码是这样的:
def destroy
respond_to do |format|
format.json do
body_hash = params[:bodyHash]
#do stuff
render json: {msg: 'User Successfully Logged out', status: 200}, status: :ok
end
format.all {render json: {msg: 'Only JSON types are supported', status: 406}.to_json, status: :ok}
end
end
解决方案
让我引用规范:
DELETE 请求消息中的有效负载没有定义的语义;在 DELETE 请求上发送有效负载正文可能会导致某些现有实现拒绝该请求。
我不会说它可以被称为使用 DELETE 请求发送有效负载的显式许可。它告诉您可以发送有效载荷,但此类请求的处理完全由服务器自行决定。
这就是发生的事情:
另一方面,它以编码方式出现,我无法检索它
为什么不能将有效负载作为 POST 请求的一部分发送,保证服务器正常处理?
推荐阅读
- python - 未能使用 ETS 进行预测
- java - 我想在后台服务中添加颜色效果或设备摄像头的任何其他更改
- python - 将一列熊猫数据框的值分配给另一列中的参数列表
- javascript - 通过 npm 运行时 Expo 发布失败
- angular - 对 Url 的 post 请求给出了被 cors 策略阻止的错误
- java - Swing 中并排的两个 BoxLayout
- android-source - Android开源库LocAPI的LocEngAdapter类中sendMsg()函数的机制
- android - 如何获取移动/桌面的设备 ID?
- selenium-webdriver - Dataprovider 并行执行测试NG
- string - 为什么排序工作表的排序顺序与 VBA 比较中的“较大”和“较小”标准之间存在差异?