Link to home
Start Free TrialLog in
Avatar of Tgerdes
TgerdesFlag for United States of America

asked on

Retreiving Form "action" value using WINHTTP.WINHTTPREQUEST object!

I am using the winhttp.winhttprequest.5 object to access a web page within an asp script using visual basic script.  I can access the web page that I need and can tell from the response headers that I have the right page.  I was wondering if there was a way to retreive the "action" attribute value of a form on the url that was requested using the send method.  I can get a the value embedded in the response headers.  Although my problem is that the length of the value of the attribute "action" changes each time so that it makes it difficult to retreive only the action value from the response headers.  Is their any way to retreive only the "action" value.
Avatar of amit_g
amit_g
Flag of United States of America image

No you cannot simply get the single attribiue value. All the posted values are separated by & and use format AttributeName=AttributeValue. So you can split the string based on separator & and then individual elements again could be splitted by separator =. Then you have both values with you.
Avatar of Tgerdes

ASKER

are you saying to split the response headers text string using an "&" what would the vbscript code look like?
Not the complete code but something like this ...

sString = "A1=AValue1&A2=AValue2"
arrNameValues = Split(sString, "&")

for i = LBound(arrNameValues) to UBound(arrNameValues)
    sNameValue = arrNameValues(i)
    arrTemp = Split(sNameValue, "=")
    sName = arrTemp(0)
    sValue = arrTemp(1)
next
Avatar of Tgerdes

ASKER

The response text that I get back is the same that you would get from viewing the source on and IE web page.  Is there another command or way to retreive the values of the form being displayed!  similar to what I would do with a "request("?????") used in vbscript?
Avatar of Tgerdes

ASKER

How do I get the "sString" array with the "A1=AValue1&A2=AValue2" in it?
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tgerdes

ASKER

I am trying to extract the action value.  This code seems to be replacing it with "$1".  How would I extract the the action value into a string!  In your example the value "TheAction.asp"
Avatar of Tgerdes

ASKER

The Answer given by amit_g was close and his pattern worked well to retreive value.  Only the code that he gave would not work to retreive the value!   I needed to use the "execute" method instead of the replace method.  The execute method can be retreived to a matches collection, and the subpattern in the pattern can be retreived to a subMatches collection!  Anyway here is the code if anyone is interested!
   
   dim oRegExp, Match, Matches, sAction, AnyString, SubMatches
   set oRegExp = new RegExp
   oRegExp.Global = True
   oRegExp.Pattern = ".*action=[""']*([^ >""']*).*"
   Set Matches = oRegExp.Execute(AnyString)
   Set Match = Matches(0)
   sAction = Match.SubMatches(0)
   Set oRegExp = Nothing
The replace also does the same thing i.e. replace the whole string with $1 and that is the first sub match i.e. the action. I was trying to save a few lines of code. Run the code as it is posted and you will see "TheAction.asp" as output in sAction.