From: 7stud -- Date: 2012-12-07T16:16:13+09:00 Subject: Re: http request Mariano Alejandro wrote in post #1087722: > Hi! > I was trying to do an http request using gem httpclient. > First at all i have to login with user and pass, if the user and pass is > correct the server send me a cookie that i have to use to other request > My code is: > > c = HTTPClient.new > c.debug_dev = STDOUT > c.set_cookie_store('cookie.dat') > request = {"user"=>"user","pass"=>"pass"} > > uri = "http://localhost/index.php" > res = c.post(uri,request,:follow_redirect => true) > puts "SALIDA: \n\n"+res.content > c.save_cookie_store > > If i look the console i can see that all is correct but i can't see > enything when i puts res.conten or res.body. Why? > Your code works fine for me. You should consider setting up a server on your computer so that you can test your web programs. Then you can write a simple cgi program to echo back some information, like the name/value pairs sent to the server in a query string(GET) or in the body of the request(POST). If the first line of the response is "HTTP/1.1 200 OK" and there is no resp.content, then the server didn't send anything back to your program. > And if i have to do more request's how do i pass the cookie to the > server? > Thank's httpclient automatically handles cookies for you--you don't have to do anything. httpclient sends back any cookies that were set by the server while your program is running. If you want to save the cookies for the next time you run your program, that's when you use set_cookie_store() and save_cookie_store(). Also, you should not be using :follow_redirect with a POST request: - (Object) post(uri, *args, &block) Sends POST request to the specified URL. See request for arguments. You should not depend on :follow_redirect => true for POST method. It sends the same POST method to the new location which is prohibited in HTTP spec. -- Posted via http://www.ruby-forum.com/.