Simple post to IIS Server using net/http

Dear All
I have a simple application that starts by sending a post to an IIS
Server with user name and password information.
Incredibly it works fine when the ruby application is run in windows,
but when run from linux the IIS server receives an empty user name and
password.
Any idea why this could be and if it is necessary to do any special
configuration from linux?
Thanks !

Test client

require ‘net/http’

begin

http = Net::HTTP.new(“192.168.101.18”,80)

POST request -> logging in

user = ARGV[0]
password = ARGV[1]
puts "Logging in as #{ARGV[0]} "
user_data = “us=#{user}&pw=#{password}”
resp = http.post(’/ca_equipos/app_cliente/acceso_app.aspx’, user_data)

etc…

Eduardo Aldaz-Carroll wrote:

puts "Logging in as #{ARGV[0]} "
user_data = “us=#{user}&pw=#{password}”
resp = http.post(’/ca_equipos/app_cliente/acceso_app.aspx’, user_data)

Just a thought, but Windows can be a little bit funny when it comes to
ARGV. It does separation differently to other shells. It might be
worthwhile checking that ARGV[0] and ARGV[1] are actually what you think
they are on each platform…

Alex Y. wrote:

Just a thought, but Windows can be a little bit funny when it comes to
ARGV. It does separation differently to other shells. It might be
worthwhile checking that ARGV[0] and ARGV[1] are actually what you think
they are on each platform…

Very good point. I develop on WinXP, and need to watch for how the
shell interprets certain characters (’&’ comes to mind) and the
inclusion of newline characters.

Might be good to write some cleanser/sanity-check helper methods to
manage input.

Even a simple logging of ARGV.inspect can be quite informative.


James B.

“People want simple stories.”

Sorry, the lines have been wrapped
this is the relevant part of the last block:
…C…q… D…E.
.C…@[email protected] $|…e…
e…P… …
…<… …N…
…us=mds 2&pw=mds
2

I’ve just done a test with ethereal, to see what was actually been
posted to the server, and indeed there is a problem:
In windows the post is correct, but in linux the values of username and
password have a space in the middle !?

As you can see in the second block, instead of having mds2 i have mds 2
!
However when i execute step by step (in komodo), or print, i can see
that ARGV[0] or ARGV[1] are correct i have indeed mds2.

POST:
0000 00 11 43 bf 2e 71 00 02 44 a1 9d ca 08 00 45 00 …C…q…
D…E.
0010 00 b7 ca c0 40 00 40 06 24 0a c0 a8 65 13 c0 a8 …@[email protected]
$…e…
0020 65 12 80 a5 00 50 fb c9 84 77 b3 aa f7 8a 80 18 e…P…
.w…
0030 05 b4 74 03 00 00 01 01 08 0a 00 8a 4e cb 00 00 …t…
…N…
0040 00 00 50 4f 53 54 20 2f 63 61 5f 65 71 75 69 70 …POST /
ca_equip
0050 6f 73 2f 61 70 70 5f 63 6c 69 65 6e 74 65 2f 61 os/app_c
liente/a
0060 63 63 65 73 6f 5f 61 70 70 2e 61 73 70 78 20 48 cceso_ap p.aspx
H
0070 54 54 50 2f 31 2e 31 0d 0a 43 6f 6e 6e 65 63 74 TTP/1.1.
.Connect
0080 69 6f 6e 3a 20 63 6c 6f 73 65 0d 0a 41 63 63 65 ion: clo
se…Acce
0090 70 74 3a 20 2a 2f 2a 0d 0a 43 6f 6e 74 65 6e 74 pt: /.
.Content
00a0 2d 4c 65 6e 67 74 68 3a 20 31 35 0d 0a 48 6f 73 -Length:
15…Hos
00b0 74 3a 20 31 39 32 2e 31 36 38 2e 31 30 31 2e 31 t: 192.1
68.101.1
00c0 38 0d 0a 0d 0a 8…

CONTINUATION:

0000 00 11 43 bf 2e 71 00 02 44 a1 9d ca 08 00 45 00 …C…q…
D…E.
0010 00 43 ca c2 40 00 40 06 24 7c c0 a8 65 13 c0 a8 .C…@[email protected]
$|…e…
0020 65 12 80 a5 00 50 fb c9 84 fa b3 aa f7 a3 80 18 e…P…

0030 05 b4 d7 3c 00 00 01 01 08 0a 00 8a 4e cc 00 09 …<…
…N…
0040 c4 04 75 73 3d 6d 64 73 32 26 70 77 3d 6d 64 73 …us=mds
2&pw=mds
0050 32 2

Very good point, i should have noticed, so it’s not a space after all…
This is the ethereal capture when ruby run on windows.

0000 00 11 43 bf 2e 71 00 09 0f 06 ff 00 08 00 45 00 …C…q…
…E.
0010 00 cf 0d e8 40 00 7f 06 e7 92 c0 a8 1f 4b c0 a8 …@…
…K…
0020 65 12 04 b8 00 50 ff fb a3 1e 2f 8c ef 5d 50 18 e…P…
…/…]P.
0030 ff ff 61 0e 00 00 50 4f 53 54 20 2f 63 61 5f 65 …a…PO ST
/ca_e
0040 71 75 69 70 6f 73 2f 61 70 70 5f 63 6c 69 65 6e quipos/a
pp_clien
0050 74 65 2f 61 63 63 65 73 6f 5f 61 70 70 2e 61 73 te/acces
o_app.as
0060 70 78 20 48 54 54 50 2f 31 2e 31 0d 0a 43 6f 6e px HTTP/
1.1…Con
0070 6e 65 63 74 69 6f 6e 3a 20 63 6c 6f 73 65 0d 0a nection:
close…
0080 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70 Content- Type:
ap
0090 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 77 77 77 2d plicatio
n/x-www-
00a0 66 6f 72 6d 2d 75 72 6c 65 6e 63 6f 64 65 64 0d form-url
encoded.
00b0 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a .Content
-Length:
00c0 20 31 35 0d 0a 48 6f 73 74 3a 20 31 39 32 2e 31 15…Hos t:
192.1
00d0 36 38 2e 31 30 31 2e 31 38 0d 0a 0d 0a 68.101.1 8…

0000 00 11 43 bf 2e 71 00 09 0f 06 ff 00 08 00 45 00 …C…q…
…E.
0010 00 37 0d e9 40 00 7f 06 e8 29 c0 a8 1f 4b c0 a8 .7…@…
.)…K…
0020 65 12 04 b8 00 50 ff fb a3 c5 2f 8c ef 76 50 18 e…P…
…/…vP.
0030 ff e6 54 89 00 00 75 73 3d 6d 64 73 32 26 70 77 …T…us
=mds2&pw
0040 3d 6d 64 73 32 =mds2

Eduardo Aldaz-Carroll [email protected] writes:

In windows the post is correct, but in linux the values of username
and password have a space in the middle !?

Actually, that’s not what you’re seeing. The attached hex dumps DO
NOT show a space in the middle of the data:

0040 c4 04 75 73 3d 6d 64 73 32 26 70 77 3d 6d 64 73 …us=mds 2&pw=mds
0050 32 2

There’s not a space in the middle of the data; ethereal just prints a
space between the first eight bytes and the last eight bytes so that
you can line it up more easily with the hex dump on the left - see the
double space in the middle of the hex dump?

A real space would be identified by a “20” in the hex dump.

However, I’m really surprised that you’re seeing something different
at all on windows vs. linux. Can you post the same portions of the
network trace from the windows machine? When I try your test http
client program here, I get the same behavior as what you posted in the
network trace from both windows and linux. (both running ruby 1.8.4)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs