Http.post 1.8.4 bug?

(Mike Lopke) #1

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

···

--
Posted via http://www.ruby-forum.com/.

(snacktime) #2

You forgot to set the content-length header.

(Bojan Mihelac) #3

Mike Lopke wrote:

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

···

--
Bojan Mihelac
Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com
-> tools, scripts, tricks from our code lab: http://source.mihelac.org

(Mike Lopke) #4

snacktime wrote:

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

···

--
Posted via http://www.ruby-forum.com/.

(Mike Lopke) #5

Bojan Mihelac wrote:

Mike Lopke wrote:

I'm talking to an ASP.NET, if that matters.
  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

Looks like I snuck in the answer before your question. :slight_smile: 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

···

--
Posted via http://www.ruby-forum.com/.

(snacktime) #6

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

···

On 8/21/06, Mike Lopke <reglopke@cableone.net> wrote:

snacktime wrote:
> 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?

(Bojan Mihelac) #7

Mike Lopke wrote:

Bojan Mihelac wrote:

Mike Lopke wrote:

I'm talking to an ASP.NET, if that matters.
  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

Looks like I snuck in the answer before your question. :slight_smile: 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 :slight_smile:

···

--
Bojan Mihelac
Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com
-> tools, scripts, tricks from our code lab: http://source.mihelac.org

(Mike Lopke) #8

snacktime wrote:

···

On 8/21/06, Mike Lopke <reglopke@cableone.net> wrote:

snacktime wrote:
> 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?

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.

--
Posted via http://www.ruby-forum.com/.

(Mike Lopke) #9

Mike Lopke wrote:

snacktime wrote:

snacktime wrote:
> 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?

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.

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

···

On 8/21/06, Mike Lopke <reglopke@cableone.net> wrote:

--
Posted via http://www.ruby-forum.com/.