Trying to post data to a session using Gnu WGET for DOS/Windows

I am using WGET to send commands to a Java Application Server.

So far, I have successfully "logged on" and been able to retrieve information from the Java Application Server into my script.

However, I am now trying to POST information to the JAS server - and this is where I am starting to get into issues.

I captured the following URL and POST information that I need to try and plug in :

URL : http://{webserver}:{port}/manage/ajax
POST Data : <request><setAttribute hostName "{hostname}" hostPort="{hostport}" objectName="jde:instanceName={JDEInstanceName},targetType=webserver,metricName=user_manager,metricType=runtime" attribute="loginDisabledMessage" value="WARNING - This System is Down currently">Warning - This System is Down currently</setAttribute></request>

The main issue is that I am using GNU Wget for DOS / Windows - and, as such, double quotes are being interpreted in DOS.  I am therefore thinking that I should be streaming the POST information using --post-file instead of --post-data, but I don't have much experience (or cannot find examples) of using this.  Any assistance would be very gratefully accepted !  Thankyou in advance....

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Put the data in a file called post.txt


wget --post-file=post.txt  http://{webserver}:{port}/manage/ajax

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
altquarkAuthor Commented:
wget is answering "Length: unspecified" - is this ok ?  Is there a way to specify the length of the post-file somehow ?
I think that's normal.  Did it transfer the text?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

altquarkAuthor Commented:
OK - excuse the long message here, but I thought it was probably time to really get into the nitty gritty (after all, I've been pulling MY hair out all day, might as well let others do the same !!!)

Here is the wget output :

--2009-07-13 14:53:59--  http://{server}:{port}/manage/ajax
Resolving {server}...
Connecting to {server}||:{port}... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified
Saving to: `TARGET/ajax'

    [ <=>                                   ] 0           --.-K/s   in 0s

2009-07-13 14:53:59 (0.00 B/s) - `TARGET/ajax' saved [0]

My issue is that the result - "Target/ajax" - is 0 bytes in length, and it seems that wget isn't sending the correct stream, or isn't waiting long enough for a response, or something weird and wonderful.

Now, I've got Wireshark - and I'm capturing the ethernet packets and performing a comparison as follows (I've had to replace some of the server names and ports due to corporate security)....

Here are the original packets :

Ôò¡          ÿÿ     aS[J®½      ¬ÆÙ? !p6kS E }¹@ ¬#

É      à#'³JæR\æPü þ
  POST /manage/ajax HTTP/1.1
Accept: */*
Accept-Language: en-us
Cache-Control: no-cache
Content-Type: text/xml; charset=UTF-8
Referer: http://{server}:{port}/manage/target?targetType=webserver&action=disableLogins
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; CON; iy1jx3hbE7tHiIVELGlZk4493682TVegQ23afJrerSNW22H9YHe7sKpDDnMY5P$#@#$i2A==; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host: {server}:{port}
Content-Length: 271
Connection: Close
Cookie: JSESSIONID=0a0ac9162327797ba6e26e784080aa12ba95443898f0
Ôò¡          ÿÿ     aS[Jν E  E   ¬ÆÙ? !p6kS E 7}º@ ¬¬z

É      à#'³MMR\æPü üµ  <request><setAttribute hostName="{serverfullURL}" hostPort="{port}" objectName="jde:instanceName={instance},targetType=webserver,metricName=user_manager,metricType=runtime" attribute="loginDisabledMessage" value=""></setAttribute></request>
Ôò¡          ÿÿ     aS[J½ê M  M   !p6kS ¬ÆÙ? E ?«@ }ï

#I#'      àR\ijN\Pü0#_  <result>
   <setAttribute hostName="{serverFull URL}" hostPort="{ServerPort}" objectName="jde:instanceName={Instance},targetType=webserver,metricName=user_manager,metricType=runtime" attribute="loginDisabledMessage" value="" result="success"/>
Note the final "success" - which indicates exactly what I want.

Now, here are the packets returned when I use WGET to perform the exact same (I hope) scenario :
Command run :

wget -nd --directory-prefix=TARGET --load-cookies cookies.txt --user-agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; CON; iy1jx3hbE7tHiIVELGlZk4493682TVegQ23afJrerSNW22H9YHe7sKpDDnMY5P$#@#$i2A==; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" --post-file=dislogins.txt http://{server}:{port}/manage/ajax

****dislogins.txt :
 <request><setAttribute hostName="{FullServerURL}" hostPort="{ServerPort}" objectName="jde:instanceName={instance},targetType=webserver,metricName=user_manager,metricType=runtime" attribute="loginDisabledMessage" value=""></setAttribute></request>

PACKET1 (Client to Server):
Ôò¡          ÿÿ     i [J)¾         ¬ÆÙ? !p6kS E òL@ ¬|-

'#'Fè\£ìU!Pü ýp  POST /manage/ajax HTTP/1.0
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; CON; iy1jx3hbE7tHiIVELGlZk4493682TVegQ23afJrerSNW22H9YHe7sKpDDnMY5P$#@#$i2A==; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Accept: */*
Host: {server}:{port}
Connection: Keep-Alive
Cookie: JSESSIONID=0a0ac9162327f18c50afc6364efe951eb85113653d1a
Content-Type: application/x-www-form-urlencoded
Content-Length: 274

PACKET2 (Client to Server):
Ôò¡          ÿÿ     i [Jh H  H   ¬ÆÙ? !p6kS E :M@ ¬|ä

'#'Fè^mìU!Pü ü¸   <request><setAttribute hostName="{ServerfullURL}" hostPort="{ServerPort}" objectName="jde:instanceName={instance},targetType=webserver,metricName=user_manager,metricType=runtime" attribute="loginDisabledMessage" value=""></setAttribute></request>

PACKET3 (Server to Client):
Ôò¡          ÿÿ     i [JR ø   ø    !p6kS ¬ÆÙ? E  ê@ }âk

'ìU!Fè_Pý#2  HTTP/1.1 200 OK
Date: Mon, 13 Jul 2009 21:00:26 GMT
Server: Oracle Containers for J2EE
Connection: close
Cache-Control: no-cache
Pragma: no-cache
Expires: Mon, 04 Dec 1999 21:29:02 GMT

altquarkAuthor Commented:
So, I'm now going through what I just posted (its good to get everything into the open)...and it seems that the packet formed by wget isn't exactly the same as the packet that IE is creating.

So, how do I get the packet to be EXACTLY the same ??!

Big differences that I see :
1. POST /manage/ajax HTTP/1.1 - can wget do HTTP1.1 ?
2. Accept-Language: en-us & Cache-Control: no-cache - can these be passed through ?
3. Content-Type: text/xml; charset=UTF-8 - this seems to be the biggy.  How do I change "content type"?
4. Referer: - do I need to put this in ?
5. Accept-Encoding: gzip, deflate - do I need to send this ?
6. Connection: Close - how do I do this ?

Thankyou for your advice.  I'm still working on this as well, using all the MAN pages I can get my hands on !
altquarkAuthor Commented:
I worked it out !!!  Yay !

Perserve and you shall wget the light !

I needed to add  :

--header="Content-Type: text/xml; charset=UTF-8"

to my wget - and lo and works !

Thankyou for your help anyway - I'll award you the points !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.