I have a problem sending request to an external server, when the token has a "+" the other server don't recognize the request. I think it's a problem of encoding (sorry I'm newbie to rails) but I don't know what to do.

This is my code

        req = Curl::Easy.new do |curl| 
        curl.url = "https://blabla.com/bla?token=#{@token}"
        curl.headers['Content-type'] = 'application/json'
    end
    req.perform
    puts req.body_str

when token is similar to: S6ps1YSMC6xaRusfSH4aBg1RTm2/U1u1ng/hZSmGGTGX12AcL//Q33ri7Wlkl1Vjg4j/zDM=

it's ok, but when is: HK+rKsYMTbs2fjN+pLfPIj5wcjZp3IVQWuK5jW0iN/wKfkVgsQAjQ5+A1RvUF1Lp0lgdf1M=

the response is 403 (forbidden).

I have searched in the docs but I have found nothing (https://github.com/taf2/curb).

Any ideas to force curl::easy to not convert the "+" in another thing?

有帮助吗?

解决方案

Try uri encoding @token before sending the request. try the 'u' method

>> u "HK+rKsYMTbs2fjN+pLfPIj5wcjZp3IVQWuK5jW0iN/wKfkVgsQAjQ5+A1RvUF1Lp0lgdf1M="
=> "HK%2BrKsYMTbs2fjN%2BpLfPIj5wcjZp3IVQWuK5jW0iN%2FwKfkVgsQAjQ5%2BA1RvUF1Lp0lgdf1M%3D"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top