# Simple post to IIS Server using net/http

**URL:** <https://www.ruby-forum.com/t/simple-post-to-iis-server-using-net-http/64156>\
**Category:** Ruby\
**Created:** [June 22, 2006, 4:06pm UTC](https://www.ruby-forum.com/t/simple-post-to-iis-server-using-net-http/64156 "2006-06-22T16:06:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ealdaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ealdaz](https://www.ruby-forum.com/u/ealdaz)\
**Post date:** [June 22, 2006, 4:06pm UTC](https://www.ruby-forum.com/t/simple-post-to-iis-server-using-net-http/64156/1 "2006-06-22T16:06:59Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![ealdaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ealdaz](https://www.ruby-forum.com/u/ealdaz)\
**Post date:** [June 22, 2006, 4:12pm UTC](https://www.ruby-forum.com/t/simple-post-to-iis-server-using-net-http/64156/2 "2006-06-22T16:12:58Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![ealdaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ealdaz](https://www.ruby-forum.com/u/ealdaz)\
**Post date:** [June 22, 2006, 5:25pm UTC](https://www.ruby-forum.com/t/simple-post-to-iis-server-using-net-http/64156/3 "2006-06-22T17:25:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ealdaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ealdaz](https://www.ruby-forum.com/u/ealdaz)\
**Post date:** [June 23, 2006, 11:48am UTC](https://www.ruby-forum.com/t/simple-post-to-iis-server-using-net-http/64156/4 "2006-06-23T11:48:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ealdaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ealdaz](https://www.ruby-forum.com/u/ealdaz)\
**Post date:** [June 23, 2006, 11:46am UTC](https://www.ruby-forum.com/t/simple-post-to-iis-server-using-net-http/64156/5 "2006-06-23T11:46:00Z")

</div>

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 …@.@.  
$…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…@.@.  
$|…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

---

<div class="post-metadata">

**Author:** ![ealdaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ealdaz](https://www.ruby-forum.com/u/ealdaz)\
**Post date:** [June 24, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/simple-post-to-iis-server-using-net-http/64156/6 "2006-06-24T18:19:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ealdaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ealdaz](https://www.ruby-forum.com/u/ealdaz)\
**Post date:** [June 24, 2006, 1:38pm UTC](https://www.ruby-forum.com/t/simple-post-to-iis-server-using-net-http/64156/7 "2006-06-24T13:38:44Z")

</div>

Eduardo Aldaz-Carroll [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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)
