# Net::HTTP working on Windows, but not Unix

**URL:** <https://www.ruby-forum.com/t/net-http-working-on-windows-but-not-unix/75895>\
**Category:** Ruby\
**Created:** [March 2, 2006, 9:04pm UTC](https://www.ruby-forum.com/t/net-http-working-on-windows-but-not-unix/75895 "2006-03-02T21:04:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [March 2, 2006, 9:04pm UTC](https://www.ruby-forum.com/t/net-http-working-on-windows-but-not-unix/75895/1 "2006-03-02T21:04:19Z")

</div>

We have an odd problem at work today.

Running the following code on Windows XP gives us a CVV2 error, which  
is what we expect (we didn’t give one). However, running the same  
code on Linux or OS X gets a complaint that we didn’t provide the  
key, which is obviously not true (see last line).

Does anyone see anything inherently non-portable in the following code?

require ‘net/http’  
require ‘net/https’

uri = URI.parse ‘[https://www.usaepay.com/gate.php](https://www.usaepay.com/gate.php)’  
p (http = Net::HTTP.new(uri.host, uri.port))  
p http.use\_ssl = true  
p http.verify\_mode = OpenSSL::SSL::VERIFY\_NONE  
p http.post(uri.path, “UMkey=OUR\_KEY\_CODE\_HERE”).body

Thanks in advance for any hints.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [March 2, 2006, 11:02pm UTC](https://www.ruby-forum.com/t/net-http-working-on-windows-but-not-unix/75895/2 "2006-03-02T23:02:32Z")

</div>

On Mar 2, 2006, at 2:03 PM, James Edward G. II wrote:

> require ‘net/http’  
> require ‘net/https’
> 
> uri = URI.parse ‘[https://www.usaepay.com/gate.php](https://www.usaepay.com/gate.php)’  
> p (http = Net::HTTP.new(uri.host, uri.port))  
> p http.use\_ssl = true  
> p http.verify\_mode = OpenSSL::SSL::VERIFY\_NONE  
> p http.post(uri.path, “UMkey=OUR\_KEY\_CODE\_HERE”).body

Switching the code to the following seems to work everywhere, as long  
as 1.8.4 is used:

require ‘net/https’

uri = URI.parse ‘[https://www.usaepay.com/gate.php](https://www.usaepay.com/gate.php)’  
req = Net::HTTP::Post.new(uri.path)  
req.set\_form\_data “UMkey” =\> “OUR\_KEY\_CODE\_HERE”  
p (http = Net::HTTP.new(uri.host, uri.port))  
p http.use\_ssl = true  
p http.verify\_mode = OpenSSL::SSL::VERIFY\_NONE  
p http.start { http.request(req) }.body

I still don’t understand why the first version didn’t work though…

James Edward G. II

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [March 3, 2006, 1:36am UTC](https://www.ruby-forum.com/t/net-http-working-on-windows-but-not-unix/75895/3 "2006-03-03T01:36:31Z")

</div>

On Mar 2, 2006, at 4:00 PM, James Edward G. II wrote:

> > code?
> 
> p http.verify\_mode = OpenSSL::SSL::VERIFY\_NONE  
> p http.start { http.request(req) }.body
> 
> I still don’t understand why the first version didn’t work though…

Sorry to keep responding to myself but we have now realized that that  
the Windows machine, where the top example originally worked, was  
running 1.8.2 while both failing machines were running 1.8.4.

The bottom “fix” did not work on the Windows box right off the bat,  
because set\_form\_data() seems to have been added after 1.8.2.  
Upgrading fixes the issue.

That raises the question of what caused the original failure though.  
Was the handling of the second parameter to post() changed between  
1.8.2 and 1.8.4? If so, I suspect there could be some more broken  
code out there…

James Edward G. II

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [March 3, 2006, 3:34am UTC](https://www.ruby-forum.com/t/net-http-working-on-windows-but-not-unix/75895/4 "2006-03-03T03:34:09Z")

</div>

On Mar 2, 2006, at 8:21 PM, Park H. wrote:

> p http.post(uri.path, “UMkey=OUR\_KEY\_CODE\_HERE”,{‘Content-Type’ =\>  
> ‘application/x-www-form-urlencoded’}).body

Awesome. Thank you so much.

> There must be a bug in 1.8.4 Net::HTTP post.  
> I suspect lib/net/http.rb line #1507
> 
> ```
> unless content_type()
> warn 'net/http: warning: Content-Type did not set; using  
> 
> ```
> 
> application/x-www-form-urlencoded’ if $VERBOSE  
> set\_content\_type ‘application/x-www-form-urlencoded’  
> end

Hmm, I’ll move this over to Ruby Core now and see if we can get the  
people in-the-know looking into this…

James Edward G. II

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [March 3, 2006, 3:22am UTC](https://www.ruby-forum.com/t/net-http-working-on-windows-but-not-unix/75895/5 "2006-03-03T03:22:05Z")

</div>

Hi,

> > > We have an odd problem at work today.
> > > 
> > > uri = URI.parse ‘[https://www.usaepay.com/gate.php](https://www.usaepay.com/gate.php)’  
> > > p (http = Net::HTTP.new(uri.host, uri.port))  
> > > p http.use\_ssl = true  
> > > p http.verify\_mode = OpenSSL::SSL::VERIFY\_NONE  
> > > p http.post(uri.path, “UMkey=OUR\_KEY\_CODE\_HERE”).body  
> > > This will work :

p http.post(uri.path, “UMkey=OUR\_KEY\_CODE\_HERE”,{‘Content-Type’ =\>  
‘application/x-www-form-urlencoded’}).body

> > > 
> > 
> > Switching the code to the following seems to work everywhere, as long as  
> > 1.8.4 is used:  
> > …
> 
> That raises the question of what caused the original failure though. Was  
> the handling of the second parameter to post() changed between 1.8.2 and  
> 1.8.4? If so, I suspect there could be some more broken code out there…

There must be a bug in 1.8.4 Net::HTTP post.  
I suspect lib/net/http.rb line #1507

```
  unless content_type()
    warn 'net/http: warning: Content-Type did not set; using

```

application/x-www-form-urlencoded’ if $VERBOSE  
set\_content\_type ‘application/x-www-form-urlencoded’  
end

Regards,

Park H.
