簡體   English   中英

使用 Ruby Rest:Client 的帶有有效負載的 DELETE 方法?

[英]DELETE method with a payload using Ruby Rest:Client?

雖然我不認為必須在 DELETE 請求中包含有效負載是很放松的。 我遇到了一個實例,在該實例中,我正在測試需要 DELETE 有效負載的服務。 有沒有辦法使用 Ruby 的 Rest Client 來完成這個? 不幸的是,我很難處理這個問題。

@json_request = '{"user_id": 5, "meta_data": "foo"}'
resource = RestClient::Resource.new "http://www.foo.com/some/process"
@response_update = resource.delete(@json_request, :content_type => :json, :accept => :json)

輸出:ArgumentError:參數數量錯誤(2 代表 0..1)

嘗試這個

RestClient::Request.execute(:method => 'delete', :url => " http://www.foo.com ", :payload => json_data)

目前,使用該寶石是不可能的。 你可以看到一個 PL 解決這個問題。 也許您可以分叉它並將這些更改拉到您自己的 rest-client gem 的分叉中。

拉取請求https://github.com/rest-client/rest-client/pull/98

作為一個非常現代的更新,來自自述文件

    RestClient::Request.execute(method: :delete, url: 'http://example.com/resource',
                                payload: 'foo', headers: {myheader: 'bar'})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM