Solved

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

Posted on 2009-07-13
6
976 Views
Last Modified: 2012-05-07
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....


0
Comment
Question by:altquark
  • 4
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
mikelfritz earned 500 total points
ID: 24840463
Put the data in a file called post.txt

Then:

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

Author Comment

by:altquark
ID: 24842933
wget is answering "Length: unspecified" - is this ok ?  Is there a way to specify the length of the post-file somehow ?
0
 
LVL 14

Expert Comment

by:mikelfritz
ID: 24843400
I think that's normal.  Did it transfer the text?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:altquark
ID: 24843960
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}... 192.168.1.22
Connecting to {server}|192.168.1.22|:{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 :

PACKET1 (from CLIENT to SERVER)
---------------
Ôò¡          ÿÿ     aS[J®½      ¬ÆÙ? !p6kS E }¹@ ¬#
#I

É      à#'³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
---------------
PACKET2 (from CLIENT to SERVER)
---------------
Ôò¡          ÿÿ     aS[Jν E  E   ¬ÆÙ? !p6kS E 7}º@ ¬¬z
#I

É      à#'³MMR\æPü üµ  <request><setAttribute hostName="{serverfullURL}" hostPort="{port}" objectName="jde:instanceName={instance},targetType=webserver,metricName=user_manager,metricType=runtime" attribute="loginDisabledMessage" value=""></setAttribute></request>
---------------
PACKET3 (from SERVER to CLIENT)
Ôò¡          ÿÿ     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"/>
</result>
---------------
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@ ¬|-
#I

É
'#'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@ ¬|ä
#I

É
'#'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

É
#I#'
'ì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





0
 
LVL 1

Author Comment

by:altquark
ID: 24844050
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 !
0
 
LVL 1

Author Comment

by:altquark
ID: 24844156
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 behold....it works !

Thankyou for your help anyway - I'll award you the points !
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Today I am discussing AJAX problems in IE7 and I bet this will helps many guys out here who have problems with AJAX work. Lets start with the discovery of problem and then we will talk about its different solutions. My last two projects included …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now