Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 2009-07-13
Medium Priority
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....

Question by:altquark
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 14

Accepted Solution

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


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

Author Comment

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

Expert Comment

ID: 24843400
I think that's normal.  Did it transfer the text?
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.


Author Comment

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


Author Comment

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 !

Author Comment

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 works !

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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

721 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