Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

manipulate .pl webpage using HTTP POST? 1

Status
Not open for further replies.

mrmovie

Technical User
Oct 2, 2002
3,094
GB
I am trying to post to a webpage which has a number of forms on it. if you browse to the webpage normally it starts off the form name jump1x, which asks you for some info, then you go to jump2x when it asks for alittle more info, finally you get to jump3x which i want to post to. i believe i have the info i need to post to jump3x but i need to figure out how to accomplish it with

strUrl = "Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
oHTTP.open "POST", strUrl, False, strU, strTimeOut


unfornately when i try and post to webpage.pl it acts as if i have landed on jump1x despite me having page=3 in the strRequest

strRequest = Escape("region=gddc&datetochange=t_end_date&page=3....etc)

....
</SCRIPT>

<form name="jump1x">
Select a Region:
<select name="myjumpbox" OnChange="top.frames['content'].location.href=jump1x.myjumpbox.options[selectedIndex].value">
<option selected>Please Select...
<option value="EditPlanMaintenance.pl?region=ams&page=1">AMS
<option value="EditPlanMaintenance.pl?region=aoa&page=1">AOA
<option value="EditPlanMaintenance.pl?region=eur&page=1">EUR
<option value="EditPlanMaintenance.pl?region=gddc&page=1">GDDC
</select><BR>
</form>

</BODY>

<form name="jump2x" action='EditPlanMaintenance.pl' method='POST'>
<input type=radio name='datetochange' value='t_start_date'>Start Date<BR>
<input type=radio name='datetochange' value='t_end_date' checked>End Date<BR><BR>
New Date:<input type='text' name='changedate' size=12 maxlength=12 value='201007291718'><BR>
(The change will only impact schedules that will have a final start date>end date)<BR><BR>
<input type='hidden' name='page' value='3'>
<input type='hidden' name='region' value="gddc">
<input type='hidden' name='where' value="where t_status<>'COMPLETED' and t_user='...User' and t_reference_number='CR000000' and t_hostname in ('machinename') ">
<input type='submit' value=' Submit '>
</form>
 
solution wasnt too bad in the end. just needed to check to change the target url to include the first forms location.ref change, so my url included EditPlanMaintenance.pl?region=gddc&page=1. this got me past the first form, then needed to get the Request string in right format including the need for a few hidden name / values.
I found the Escape() function helpful.
 
[0] It depends on how determined is the site to enforce the requirement the user have to submit successively the page, such as setting certain server-side variables or cookies... that would make direct submitting to the 3rd page more difficult to achieve.

[1] Suppose the page containing the form jump1x is the page 1, the page in the frame 'content' is the 2nd page, and that the page with jump2x is the 3rd page. The purpose is to directly submit to the 3rd with the action EditPlanMaintenance.pl.

[1.1] First, some observation. The "submit" in a sense from the onchange handler looks not very generic (probably work on ie only.) To make it more robust, I would say this?
>OnChange="top.frames['content'].location.href=jump1x.myjumpbox.options[selectedIndex].value"
[tt]OnChange="top.frames['content'].location.href=[red]this.form.[/red]myjumpbox.options[selectedIndex].value"[/tt]
or simply this.
[tt]OnChange="top.frames['content'].location.href=[red]this.form.[/red]myjumpbox.[blue]value[/blue]"[/tt]

[2] From the look of the 3rd page, some data submitted through method get are re-coded in hidden input box and I think that might be the only thing that make successive traversal of page1 and page2 needed. If that is the case, you can surely directly submit to the final targetted page.

[2.1] You need to set the content-type to make post process properly at the server. (The way you said with ?region=gddc... is properly belonging to the get method rather than the post method!?)

[2.2] The xmlhppt script looks something like this. (Are you sure the strTimeout's meaning?)
[tt]
[green]strUrl="[ignore][/ignore]"
strUsr="xxx"
strPwd="yyy"[/green]

'construction of the message to post (details to construct)
smsg="datetochange=" & escape("t_end_date") 'key=value encodeuri needed in general
smsg=smsg & "&" & "page=" & escape("3")
smsg=smsg & "&" & "region=" & escape("gddc")
smsg=smsg & "&" & "where=" & escape("where t_status<>'COMPLETED' and t_user='...User' and t_reference_number='CR000000' and t_hostname in ('machinename')")


Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
oHTTP.open "POST", strUrl, False, strUsr, strPwd
'this is important
[blue]oHTTP.setRequestHeader "Content-Type","application/x-www-form-urlencoded"[/blue]
oHTTP.send smsg

sresponse=oHTTP.responseText 'do whatever
[/tt]
 
thanks Tsuji, i knew you would be the one with the knowledge ;-)
The POST seems to be working as you have indicated and i am getting a positive response in the .responseText. The webpage owner has told me he doesnt support directly posting to the 3rd page but i think that is more a case that he hasnt tested it.

the code i am using for the post is below.
i am hitting

with a query string like you suggest

The last thing that is on my mind is that i have seen some looping code around the oHTTP.send method, seemingly waiting for the websites response, as if oHTTP.send method isnt a blocked method?


Function HTTPPost(strUrl, strRequest, strU, strTimeOut)
On Error Resume Next
Dim oHTTP, intTemp, strTemp
Call DisplayMsg ("HTTPPost:strUrl=" & strUrl, False, True)
Call DisplayMsg ("HTTPPost:strRequest=" & strRequest, False, True)
Call DisplayMsg ("HTTPPost:strU=" & strU, False, True)
Err.Clear
'Set oHTTP = CreateObject("Microsoft.XMLHTTP")
' Set oHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
'Set oHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
intTemp = Err.Number
Call DisplayMsg ("HTTPPost:intTemp, Err.Number after CreateObject(Microsoft.XMLHTTP)=" & CStr(intTemp), False, True)
Err.Clear
oHTTP.open "POST", strUrl, False, strU, strTimeOut
Err.Clear
oHTTP.SetOption 2, 13056
Call DisplayMsg ("HTTPPost:after option2" & Err.Number, False, True)
Err.Clear
' oHTTP.SetOption 3, "LOCAL_MACHINE\My\iammmdev.globedev.ddc"
Call DisplayMsg ("HTTPPost:after option3" & Err.Number, False, True)
intTemp = Err.Number
Call DisplayMsg ("HTTPPost:intTemp, Err.Number oHTTP.open=" & CStr(intTemp), False, True)
oHTTP.setRequestHeader "Content-Type", "application/x- oHTTP.setRequestHeader "Content-Length", Len(strRequest)
Err.Clear
oHTTP.send strRequest
intTemp = Err.Number
strTemp = Err.Description
Call DisplayMsg ("HTTPPost:intTemp, Err.Number oHTTP.send=" & CStr(intTemp), False, True)
Call DisplayMsg ("HTTPPost:strTemp, Err.Description oHTTP.send=" & strTemp, False, True)
HTTPPost = oHTTP.responseText
On Error GoTo 0
End Function
 
tsuji,
i understand you point with regards the query string only being needed for a GET, i will try and remove it and test that it works, thanks.
if i had the time i think i would code something which uses a GET first with the query string, then uses the response to formulate the required POST, I dont have the resource at the moment
 
[1.1.1] I meant also, or as an alternative, simply this!
[tt]OnChange="top.frames['content'].location.href=this.value"[/tt]
 
thanks tsuji, the webpage isnt my code to modify and me making a suggestion for improvement may not be welcome :)
The removal of the query string from the strUrl for the POST works fine, thanks for that.
 
the strTimeOut is just a reluctance to have a variable called strPassword ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top