# REST web service POST 401 Unauthorized error

**URL:** <https://www.ruby-forum.com/t/rest-web-service-post-401-unauthorized-error/126286>\
**Category:** Rails\
**Created:** [January 16, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/rest-web-service-post-401-unauthorized-error/126286 "2008-01-16T23:56:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@Erwin](https://www.ruby-forum.com/u/Erwin)\
**Post date:** [January 16, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/rest-web-service-post-401-unauthorized-error/126286/1 "2008-01-16T23:56:06Z")

</div>

I am trying to set up REST web service w Rails 2.0.2,

I don’t have any problem with the GET

url = “http://#{WWW\_HOST}/posts/online.xml”  
result = Net::HTTP.get(URI(url))  
I get the expected result

but when I try to use a POST,  
url = URI.parse(“http://#{WWW\_HOST}//user/posts/createReference.xml”)  
… post\_args1,…post\_args2…  
resp, data = Net::HTTP.post\_form(url, {post\_args1, post\_args2} )

I get a 401 Unauthorized error  
(ERROR TYPE: ActionController::InvalidAuthenticityToken)

In my server PostsController, I have a filter , but I wrote :  
class PostsController \< ApplicationController  
before\_filter :login\_required, :except =\>  
[:online, :createReference]  
so the login is not required for both actions online and  
createReference

in my routes I have :  
map.resources :posts, :collection =\> {:online =\> :get}  
and  
map.resource :user, :controller =\> “users” do |user|  
user.resources :posts, :collection =\> {:createReference =\> :post }  
end

I know that AuthenticityToken is quite new with 2.0 and forms  
I am using

class ApplicationController \< ActionController::Base  
include AuthenticationSystem,  
protect\_from\_forgery

where should I start to investigate ?

thanks for your help
