Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Net::HTTP working on Windows, but not Unix

Reply
Thread Tools

Net::HTTP working on Windows, but not Unix

 
 
James Edward Gray II
Guest
Posts: n/a
 
      03-02-2006
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'
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 Gray II



 
Reply With Quote
 
 
 
 
James Edward Gray II
Guest
Posts: n/a
 
      03-02-2006
On Mar 2, 2006, at 2:03 PM, James Edward Gray II wrote:

> 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'
> 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'
req = Net::HTTP:ost.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 Gray II



 
Reply With Quote
 
 
 
 
James Edward Gray II
Guest
Posts: n/a
 
      03-03-2006
On Mar 2, 2006, at 4:00 PM, James Edward Gray II wrote:

> On Mar 2, 2006, at 2:03 PM, James Edward Gray II wrote:
>
>> 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'
>> 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'
> req = Net::HTTP:ost.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...


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 Gray II



 
Reply With Quote
 
Park Heesob
Guest
Posts: n/a
 
      03-03-2006


Hi,

>From: James Edward Gray II <(E-Mail Removed)>
>Reply-To: http://www.velocityreviews.com/forums/(E-Mail Removed)
>To: (E-Mail Removed) (ruby-talk ML)
>Subject: Re: Net::HTTP working on Windows, but not Unix
>Date: Fri, 3 Mar 2006 09:35:13 +0900
>
>On Mar 2, 2006, at 4:00 PM, James Edward Gray II wrote:
>
>>On Mar 2, 2006, at 2:03 PM, James Edward Gray II wrote:
>>
>>>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'
>>> 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:

...
>>
>>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...
>

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 Heesob




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Working in Unix but not in windows sanjaymeher@gmail.com C Programming 12 12-28-2005 08:52 AM
Cookies working on intranet but NOT working on Internet Martin Heuckeroth ASP .Net 5 04-01-2005 01:37 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C Programming 18 01-10-2005 03:35 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C++ 12 01-10-2005 03:35 AM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-22-2004 10:59 PM



Advertisments