我正在尝试使用 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