Greetings all. Ruby n00b here.
I'm trying to use Ruby against ning.com's REST api. My code is close
to working, but I don't understand the redirect example provided in
the Net::HTTP code. I'm hoping that someone can point me in the right
direction.
--- Here's my code ---
#create XML message
msg = <<eof
blah blah
eof
doc = REXML::Document.new( msg )
url = URI.parse("https://mySite.ning.com/xn/atom/1.0/content")
@req = Net::HTTP.new(url.host)
@req.use_ssl = false #not using ssl
@req.set_debug_output $stderr
@req.start() do |req|
postReq = Net::HTTP::Post.new(url.path)
postReq.basic_auth('user', 'password')
postReq['Content-Type']=req.head(url.path)
postReq.body = doc
print postReq
response = req.post(url.path, postReq)
end
This results in the following at the command line when I run:
<- "HEAD /xn/atom/1.0/content HTTP/1.1\r\nAccept: */*\r\nHost:
mySite.ning.com\r\n\r\n"
-> "HTTP/1.1 302 Moved Temporarily\r\n"
-> "Date: Fri, 15 Feb 2008 00:45:18 GMT\r\n"
-> "Server: Ning HTTP Server 2.0\r\n"
-> "Expires: Thu, 01 Jan 1970 00:00:00 GMT\r\n"
-> "Set-Cookie: xn_visitor=438cccb8-1919-404e-874c-
b5791b46c579;Path=/;Domain=.ning.com;Expires=Mon, 12-Feb-18 00:45:18
GMT\r\n"
-> "X-XN-Trace: e1355fab-b1f3-409a-95bc-72488878cf37\r\n"
-> "Date: Fri, 15 Feb 2008 00:45:18 GMT\r\n"
-> "X-XN-Trace: e1355fab-b1f3-409a-95bc-72488878cf37\r\n"
-> "P3P: CP=\"UNI STA LOC CURa OURa COR ALL IND\"\r\n"
-> "Vary: X-XN_APPLICATION\r\n"
-> "Content-Type: text/html; charset=utf-8\r\n"
-> "Content-Language: en\r\n"
-> "Location:
http://mySite.ning.com/main/authorization/signIn?target=http%3A%2F%2FmySite.ning.com%2Frest%2Funsupported-http-method\r\n"
-> "Content-Length: 0\r\n"
-> "\r\n"
Conn keep-alive
#<Net::HTTP::Post:0x2ede408><- "POST /xn/atom/1.0/content HTTP/1.1\r
\nAccept: */*\r\nContent-Type: application/x-www-form-urlencoded\r
\nContent-Length: 3\r\nHost: mySite.ning.com\r\n\r\n"
<- c:/ruby/lib/ruby/1.8/net/protocol.rb:174:in `write0': undefined
method `dump' for #<Net::HTTP::Post POST> (NoMethodError)
from c:/ruby/lib/ruby/1.8/net/protocol.rb:151:in `write'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:166:in `writing'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:150:in `write'
from c:/ruby/lib/ruby/1.8/net/http.rb:1549:in
`send_request_with_body'
from c:/ruby/lib/ruby/1.8/net/http.rb:1534:in `exec'
from c:/ruby/lib/ruby/1.8/net/http.rb:1057:in `request'
from c:/ruby/lib/ruby/1.8/net/http.rb:854:in `post'
from ning_send.rb:50
from c:/ruby/lib/ruby/1.8/net/http.rb:547:in `start'
from ning_send.rb:39
Anyone have any suggestions? So clueless here.