# Need help with Net::HTTP Post

**URL:** <https://www.ruby-forum.com/t/need-help-with-net-http-post/161405>\
**Category:** Ruby\
**Created:** [February 26, 2009, 8:39am UTC](https://www.ruby-forum.com/t/need-help-with-net-http-post/161405 "2009-02-26T08:39:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [February 26, 2009, 8:39am UTC](https://www.ruby-forum.com/t/need-help-with-net-http-post/161405/1 "2009-02-26T08:39:18Z")

</div>

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("", 8080)  
h.post(’/test/test1’,fd.read)

Thanks for the help in advance

Regards,  
Sudhi

---

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [February 26, 2009, 2:22pm UTC](https://www.ruby-forum.com/t/need-help-with-net-http-post/161405/2 "2009-02-26T14:22:22Z")

</div>

Sudhi K. 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("", 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.

---

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [February 26, 2009, 2:54pm UTC](https://www.ruby-forum.com/t/need-help-with-net-http-post/161405/3 "2009-02-26T14:54:11Z")

</div>

Brian C. wrote:

> Sudhi K. 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("", 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

---

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [February 26, 2009, 9:00pm UTC](https://www.ruby-forum.com/t/need-help-with-net-http-post/161405/4 "2009-02-26T21:00:23Z")

</div>

Sudhi K. 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)
