我在上传文件时遇到了rest-client gem的以下错误。宝石已正确安装。
require 'rest-client'
class SimpleService
include RestClient
// other methods //
def update_request method, opts ={}
headers = set_request_header
payload = opts
url = @base_uri + url_path(method)
begin
# RestClient.put url, payload, headers
RestClient::Request.execute(method: :put, url: url,
payload: payload, headers: headers)
rescue RestClient::ExceptionWithResponse => e
byebug
e.response
end
end
end
其余客户端的参数是
headers is {"Authorization"=>"ApiKey SHctT2tSNE94Ijp0cnVlfQ.4ylSKUJurtqCqfiNcm2vRROyHyWjJxWi0WFLsABLY74", "content_type"=>"json"}
url is "https://sandbox.test-simplexcc.com/v2/users/604776/kyc"
payload is <ActionController::Parameters {"identity_kyc_docunt_1"=>#<ActionDispatch::Http::UploadedFile:0x007fe2183a6d10 @tempfile=#<Tempfile:/var/folders/95/z56d5kd10_sb7s82b982fpjw0000gn/T/RackMultipart20180628-1288-1oncnou.png>, @original_filename="35155-6-adventure-time-picture.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"identity_kyc_docunt_1\"; filename=\"35155-6-adventure-time-picture.png\"\r\nContent-Type: image/png\r\n">, "controller"=>"simplex", "action"=>"update_kyc"} permitted: true>
我正在使用邮递员客户打电话给我的休息终点。对于每个请求,我都会遇到相同的错误。
(byebug) e
#<RestClient::NotFound: 404 Not Found>
我尝试了其他rest client gem调用来调用端点。对于我遇到的所有错误,同样如此。
谢谢 阿吉斯
答案 0 :(得分:0)
我不得不将有效载荷转换为json并解决了问题。
RestClient::Request.execute(method: :put, url: url,
payload: payload.to_json, headers: headers)