For Basic Auth, you should be able to set the user and password in plaintext when you create the resource:
resource = RestClient::Resource.new( 'http://example.com', 'user', 'password' )
But if you really need to set the header directly per request:
@response = resource.post( request_payload, :Authorization => $auth )
should work. If it does not, then you may have set $auth
incorrectly. However, I think you just missed adding the request payload, so it was using the hash you supplied for that required param, and not setting any headers at all.
Here's a complete and working example using get
(I don't have a test service available with Basic Auth and POST)
require 'rest-client'
require 'base64'
$auth = 'Basic ' + Base64.encode64( 'user:passwd' ).chomp
$url = 'http://httpbin.org/basic-auth/user/passwd'
@resource = RestClient::Resource.new( $url )
@response = @resource.get( :Authorization => $auth )
# => "{\n \"authenticated\": true,\n \"user\": \"user\"\n}"
Note: Though this works, I recommend you use the first and simplest method of supplying user and password to the constructor unless you have good reason not to.