?
Solved

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

Posted on 2003-11-11
9
Medium Priority
?
2,060 Views
Last Modified: 2010-07-27
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.
0
Comment
Question by:Tgerdes
[X]
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
  • 5
  • 4
9 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 9726095
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.
0
 
LVL 1

Author Comment

by:Tgerdes
ID: 9726254
are you saying to split the response headers text string using an "&" what would the vbscript code look like?
0
 
LVL 58

Expert Comment

by:amit_g
ID: 9726318
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:Tgerdes
ID: 9726369
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?
0
 
LVL 1

Author Comment

by:Tgerdes
ID: 9726395
How do I get the "sString" array with the "A1=AValue1&A2=AValue2" in it?
0
 
LVL 58

Accepted Solution

by:
amit_g earned 1500 total points
ID: 9726604
Oh I got it wrong. I thought you are getting the posted values. You are getting the the complete HTML in the response. It is little difficult to get the action but you can try regular expresstion ...

<%
      Dim oRegExp, sString, sAction

      sString = "<form name=""annything"" action=""TheAction.asp"">"
      'sString = "<form name=""annything"" action='TheAction.asp'>"
      'sString = "<form name=""annything"" action=TheAction.asp>"

      Set oRegExp = New RegExp
      oRegExp.Global = True
      oRegExp.Pattern = ".*action=[""']*([^ >""']*).*"
      sAction = oRegExp.Replace(sString, "$1")
      Response.Write sAction
      Set oRegExp = Nothing
%>
0
 
LVL 1

Author Comment

by:Tgerdes
ID: 9733973
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"
0
 
LVL 1

Author Comment

by:Tgerdes
ID: 9735108
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
0
 
LVL 58

Expert Comment

by:amit_g
ID: 9735252
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

752 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