简体   繁体   中英

#<RestClient::NotFound: 404 Not Found> error + rest-client gem

I'm getting the below error for rest-client gem while file uploading. Gem is installed properly.

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

parameters for the rest client is

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>

I'm using the postman client call my rest end points. for every request im getting the same error.

(byebug) e
#<RestClient::NotFound: 404 Not Found>

I tried other rest client gem calls to invoke the endpoints. for everything i'm getting the same error.

Thanks Ajith

I had to convert the payload to json and it solved the problem.

RestClient::Request.execute(method: :put, url: url,
                            payload: payload.to_json, headers: headers)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM