http.post 1.8.4 bug?

M

Mike Lopke

I'm having a problem with http.post for ruby 1.8.4. Specifically, the
server I'm posting to is complaining that it is not getting all the
parameter I'm sending.

This code snippet works in version 1.8.2 but fails in 1.8.4

@http = Net::HTTP.new( server, port )
@headers['Content-Type'] = 'text/html'
data = 'Type=METADATA-SYSTEM&ID=0'
resp = @http.post(uri,data,@headers )


The server I'm posting appears to only get the first parameter
'Type=METADATA' but is complaining that the second paramert 'ID=0' is
missing. Switching order doesn't matter.

There was a similar issue reported on rubyforge.
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=4782&group_id=426
I updated the feedvalidator and am also manually setting the
content-type but nothing seems to work.

I'm talking to an ASP.NET, if that matters.



Making things more confusing, this bit of code seems to work.

require 'net/http'

Net::HTTP.start('www.snee.com', 80) {|http|
result = http.post('/xml/crud/posttest.cgi',
'fname=works&lname=here')
puts result
}


Any help would be greatly appreciated!

Regards,
Mike
 
M

Mike Lopke

snacktime said:
You forgot to set the content-length header.

Thanks, I tried it but I'm still getting the error. The code works fine
in 1.8.2 and I don't have to set content-length. I think it might be
something else.

Would there be a reason I'd need to set this in 1.8.4 and not in 1.8.2
to get http.post to work correctly?

Mike
 
S

snacktime

Thanks, I tried it but I'm still getting the error. The code works fine
in 1.8.2 and I don't have to set content-length. I think it might be
something else.

Would there be a reason I'd need to set this in 1.8.4 and not in 1.8.2
to get http.post to work correctly?

Aren't dashes supposed to be escaped? You might try escaping the post
data and see if that does it.
 
M

Mike Lopke

snacktime said:
Aren't dashes supposed to be escaped? You might try escaping the post
data and see if that does it.

Tried it just for grins and still get the same issue. Odd thing, It
doens't appear to be related to order or number of parameters.
 
M

Mike Lopke

Mike said:
Tried it just for grins and still get the same issue. Odd thing, It
doens't appear to be related to order or number of parameters.

Just an FYI for anyone else who comes uppon this, I figured out what my
problem was.

This line:
@headers['Content-Type'] = 'text/html'

Should have been:
@headers['content-type'] = 'application/x-www-form-urlencoded'

I didn't have the content-type set correctly. With 1.8.4 you have to
explicitly set it. ( This was the but and it has been fixed, from what
I gather. ) I just was not setting it to the correct value.

Cheers,
Mike
 
B

Bojan Mihelac

Mike said:
I'm having a problem with http.post for ruby 1.8.4. Specifically, the
server I'm posting to is complaining that it is not getting all the
parameter I'm sending.

This code snippet works in version 1.8.2 but fails in 1.8.4

@http = Net::HTTP.new( server, port )
@headers['Content-Type'] = 'text/html'
data = 'Type=METADATA-SYSTEM&ID=0'
resp = @http.post(uri,data,@headers )


The server I'm posting appears to only get the first parameter
'Type=METADATA' but is complaining that the second paramert 'ID=0' is
missing. Switching order doesn't matter.

There was a similar issue reported on rubyforge.
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=4782&group_id=426
I updated the feedvalidator and am also manually setting the
content-type but nothing seems to work.

I'm talking to an ASP.NET, if that matters.



Making things more confusing, this bit of code seems to work.

require 'net/http'

Net::HTTP.start('www.snee.com', 80) {|http|
result = http.post('/xml/crud/posttest.cgi',
'fname=works&lname=here')
puts result
}


Any help would be greatly appreciated!

Regards,
Mike

Hi Mike,
I have similiar problem trying to proxy PHP application. Did you found
any solution?

best regards,
Bojan Mihelac
 
M

Mike Lopke

Bojan said:
Hi Mike,
I have similiar problem trying to proxy PHP application. Did you found
any solution?

best regards,
Bojan Mihelac

Looks like I snuck in the answer before your question. :) Setting the
content-type to the correct value fixed things for me. For ruby 1.8.4
you have to manually set it. See the link to the bug earlier in the
thread.

Hope this helps with your problem.

Mike
 
B

Bojan Mihelac

Mike said:
Looks like I snuck in the answer before your question. :) Setting the
content-type to the correct value fixed things for me. For ruby 1.8.4
you have to manually set it. See the link to the bug earlier in the
thread.

Hope this helps with your problem.

Mike

Thanks Mike,
this saves my day :)
 

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,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top