Advice for Net::HTTP class

B

Bojan Mihelac

Hello,
I am loosing myself with Net:HTTP class, following
HowToRenderProxiedPages article I cannot make post method to proxy
parameters to web page.


require 'net/http'
### p.php <?php print_r($_POST)?>

### 1. does not work
response = Net::HTTP.start('localhost', 80) { |http|
http.post('/p.php', 'query=ruby')
}
puts response

### 2. works
response = Net::HTTP.post_form(URI.parse('http://localhost/p.php'), {
"query" => "ruby"})
puts response


Can anyone please explain me why the first one doesn't work? (I am using
Ruby 1.8.4, tested both linux and win)

thanx,
Bojan Mihelac
 
B

Bojan Mihelac

Bojan said:
Hello,
I am loosing myself with Net:HTTP class, following
HowToRenderProxiedPages article I cannot make post method to proxy
parameters to web page.


require 'net/http'
### p.php <?php print_r($_POST)?>

### 1. does not work
response = Net::HTTP.start('localhost', 80) { |http|
http.post('/p.php', 'query=ruby')
}
puts response

### 2. works
response = Net::HTTP.post_form(URI.parse('http://localhost/p.php'), {
"query" => "ruby"})
puts response


Can anyone please explain me why the first one doesn't work? (I am using
Ruby 1.8.4, tested both linux and win)

thanx,
Bojan Mihelac
thnx Mike L. for solution:

headers['content-type'] = 'application/x-www-form-urlencoded' if method
=='POST'
http.post('/p.php', 'query=123ruby', headers)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top