Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Enterprise Tools / September 2005

Tip: Looking for answers? Try searching our database.

Microsoft application center test...oResponse.body parsing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cpavon@gmail.com - 31 Aug 2005 17:41 GMT
Hello everyone,

I am fairly new to MACT, I am currently trying to parse the
oResponse.Body to retrive a dynamic values...store in an array and then

randomly post those values.

Does anyone have any sample code on how to parse the oResponse.Body?

This is what I have so far but I cannot seem to get the value I'm
trying to pick up.
I have been struguling on getting this values for a couple of days now.

The line of source code I'm trying to pickup displays as follows:
<form name="form2" action="/emobile/l.cfm" method="post">
<input type="hidden" name="params"
value="RAND;3928;P_TYPE;0;MYST­ATUS;5;AREA;2;SD;0;SEARCH;Sear­ch;"/>

I would like to grab value and store it somewhere.

Thanks in advance.

'-----------------------------­---------------
' Here I'm posting my random search critieria
' and then it will return a page with the results in a form
' of links.  The links area property address'
'

Sub SendRequest9()
   Dim oConnection, oRequest, oResponse, oHeaders, strStatusCode
   If fEnableDelays = True then Test.Sleep (20051)
   Set oConnection = Test.CreateConnection(sSiteNam­e, 80, false)
   If (oConnection is Nothing) Then
       Test.Trace "Error: Unable to create connection to " & sSiteName

   Else
       Set oRequest = Test.CreateRequest
       oRequest.Path = "/emobile/l.cfm"
       oRequest.Verb = "POST"
       oRequest.HTTPVersion = "HTTP/1.0"
       oRequest.EncodeBody = False
       set oHeaders = oRequest.Headers
       oHeaders.RemoveAll
       oHeaders.Add "Accept", "image/gif, image/x-xbitmap, image/jpeg,

image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*"
       oHeaders.Add "Referer", "http://" & sSiteName &
"/emobile/cr.cfm"
       oHeaders.Add "Accept-Language", "en-us"
       oHeaders.Add "Content-Type",
"application/x-www-form-urlenc­oded"
       oHeaders.Add "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR
2.0.50215)"
       'oHeaders.Add "Host", sSiteName
       oHeaders.Add "Host", "(automatic)"
       oHeaders.Add "Pragma", "no-cache"
       oHeaders.Add "Cookie", "(automatic)"
       oHeaders.Add "Content-Length", "(automatic)"
'               Test.TraceLevel= -1
       oRequest.Body = "randˆ33&p_type=" & GetRandomPropertyType &
"mystatus=" & GetRandomStatus & "area=" & GetRandomArea &
"st=&streetnu"
           oRequest.Body = oRequest.Body +
"m1=&streetnum2=&zip_code=&lp1­=" &
GetRandomPrice1 & "lp2=" & GetRandomPrice2 & "br1=" & GetRandomBed1
       oRequest.Body = oRequest.Body + "br2="& GetRandomBed2& "ba1=" &

GetRandomBath1 & "ba2=" & GetRandomBath2 &
"sf1=&sf2=&lsz1=&lsz2=&unt1=&u­nt2"
       oRequest.Body = oRequest.Body + "=&sd=0&Search=Search"
       Set oResponse = oConnection.Send(oRequest)
       If (oResponse is Nothing) Then
           Test.Trace "Error: Failed to receive response for URL to "
+ "/emobile/l.cfm"
       Else
           strStatusCode = oResponse.ResultCode
       End If
       oConnection.Close
   End If
End Sub

'---------------------
' here I am trying to parse the oResponse.body but get
' nothing using the InStr towards the end of the Sub.  I also tried
' the code on the sub above right after the If (oResponse Nothing)
' Then
Else
 'Begin params parsing

Sub SendRequest10()
   Dim oConnection, oRequest, oResponse, oHeaders, strStatusCode
   Dim oUser, Pos1, Pos2, sParams
   If fEnableDelays = True then Test.Sleep (287)
   Set oConnection = Test.CreateConnection(sSiteNam­e, 80, false)
   If (oConnection is Nothing) Then
       Test.Trace "Error: Unable to create connection to " & sSiteName

   Else
       Set oRequest = Test.CreateRequest
       Set oUser = Test.GetCurrentUser
       oRequest.Path = "/emobile/l.cfm"
       oRequest.Verb = "GET"
       oRequest.HTTPVersion = "HTTP/1.0"
       set oHeaders = oRequest.Headers
       oHeaders.RemoveAll
       oHeaders.Add "Accept", "*/*"
       'Test.Trace("*****************­*********" & oUser.Name & "
RETRIEVING RESULTS***********************­***")
       oHeaders.Add "Referer", "http://" & sSiteName &
"/emobile/l.cfm"
       oHeaders.Add "Accept-Language", "en-us"
       oHeaders.Add "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR
2.0.50215)"
       'oHeaders.Add "Host", sSiteName
       oHeaders.Add "Host", "(automatic)"
       oHeaders.Add "Cookie", "(automatic)"
       Set oResponse = oConnection.Send(oRequest)
       If (oResponse is Nothing) Then
           Test.Trace "Error: Failed to receive response for URL to "
+ "/CFIDE/debug/images/topdoc.gi­f"
       Else
                       'Begin params parsing
           If InStr(oResponse.Body, "params") Then
                               Pos1 = InStr(InStr(oResponse.Body,
"params"), oResponse.Body,
"value=")
                               Pos2 = InStr(Pos1, oResponse.Body,
"/>")
                               sParams = Mid(oResponse.Body, Pos1,
Pos2)
                               Test.Trace "params 2= " & sParams
                       End If
           strStatusCode = oResponse.ResultCode
           'Test.Trace "params = " & sParams
       End If
       oConnection.Close
   End If
End Sub
John White - 06 Sep 2005 16:02 GMT
Hi,

Try using RegExp object instead of instr, also makesure your response buffer
is large enough to hold the complete response string you want to parse.

There are lots of examples on the web for both points.

Good luck

John

> Hello everyone,
>
[quoted text clipped - 137 lines]
>     End If
> End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.