Forum: Ruby Need help with Net::HTTP Post

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C95664a5c59ccdfb0da2f5910675c62c?d=identicon&s=25 Sudhi Kulkarni (sudhi)
on 2009-02-26 08:39
Hi,

I am trying do a Net::HTTP post, the post returns with a 201 Created but
still the thread executing the script is stuck until Read Timeout
occurs. Need help to understand how to comeout of the Post when a
response is obtained. The code snippet I am using is as below

  fd= File.open("test.xml","rb")
  h = Net::HTTP.new("<ip-address>", 8080)
  h.post('/test/test1',fd.read)

Thanks for the help in advance

Regards,
Sudhi
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2009-02-26 14:22
Sudhi Kulkarni wrote:
> Hi,
>
> I am trying do a Net::HTTP post, the post returns with a 201 Created but
> still the thread executing the script is stuck until Read Timeout
> occurs. Need help to understand how to comeout of the Post when a
> response is obtained. The code snippet I am using is as below
>
>   fd= File.open("test.xml","rb")
>   h = Net::HTTP.new("<ip-address>", 8080)
>   h.post('/test/test1',fd.read)

How do you know the post returns with a 201, if it isn't getting past
the h.post line?

Best way to find out what's going on is with tcpdump or wireshark.

It's possible that there's some HTTP/1.1 nastiness going on, e.g. one
side thinks the connection should remain open whilst the other thinks it
should be closed, possibly combined with a missing Content-Length:
header from one side or the other.
C95664a5c59ccdfb0da2f5910675c62c?d=identicon&s=25 Sudhi Kulkarni (sudhi)
on 2009-02-26 14:54
Brian Candler wrote:
> Sudhi Kulkarni wrote:
>> Hi,
>>
>> I am trying do a Net::HTTP post, the post returns with a 201 Created but
>> still the thread executing the script is stuck until Read Timeout
>> occurs. Need help to understand how to comeout of the Post when a
>> response is obtained. The code snippet I am using is as below
>>
>>   fd= File.open("test.xml","rb")
>>   h = Net::HTTP.new("<ip-address>", 8080)
>>   h.post('/test/test1',fd.read)
>
> How do you know the post returns with a 201, if it isn't getting past
> the h.post line?
>
> Best way to find out what's going on is with tcpdump or wireshark.
>
> It's possible that there's some HTTP/1.1 nastiness going on, e.g. one
> side thinks the connection should remain open whilst the other thinks it
> should be closed, possibly combined with a missing Content-Length:
> header from one side or the other.

Hi,
That is exactly what I had done, Wireshark shows that the response is
obtained as 201 created but then the script still continues to wait...

Thanks,
Sudhi
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2009-02-26 21:00
Sudhi Kulkarni wrote:
> That is exactly what I had done, Wireshark shows that the response is
> obtained as 201 created but then the script still continues to wait...

OK, so post the full, exact headers of both the request and the
response.

If the response contains a Content-Length: header, check that the
response body has exactly that many bytes (counting after the \r\n\r\n
which terminates the headers)
This topic is locked and can not be replied to.