Help with ie.navigate and POST data using PureDispHelper

Just starting out? Need help? Post your questions and find answers here.
User avatar
singo
User
User
Posts: 35
Joined: Mon Apr 23, 2007 4:50 am
Location: Nabiac NSW Australia

Help with ie.navigate and POST data using PureDispHelper

Post by singo »

I am trying to extend the ie_navigate example to POST data to a php web page, the page opens but no data is posted.

Can anyone offer some suggestions ? I have tried with and without the Base64Encoder.

Code: Select all

; based on FreeBASIC example
; changed to PB by ts-soft
; changed by Singo to try and post data to php page

EnableExplicit

Define.l ieApp, flags=0
Define.s post_data,base_data,url,targetframe="",headers

dhToggleExceptions(#True)

ieApp = dhCreateObject("InternetExplorer.Application")

If ieApp

  dhPutValue (ieApp, "Visible = %b", #True)

  url = "10.0.0.155/q/qtest.php"
  post_data = "email=myemail@mail.com.au&name=myname"
  base_data = Space(512)
  Base64Encoder(@post_data,Len(post_data),@base_data,512)
  base_data=Trim(base_data)

  headers = "Content-Type: application/x-www-form-urlencoded" +Chr(13)+Chr(10)
  
  dhCallMethod(ieApp, "Navigate(%T,%d,%s,%s,%s)", @url,flags,@targetframe,@base_data,@headers)
  dhReleaseObject(ieApp) : ieApp = 0
  
EndIf
Thanks
Singo
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

Why do you encode the data?
Your content header is not set to let the webserver/app recognize the data.
Also what's with the 512 bytes.

Post data (afaik) requires names for each element.
I would debug an ordinary html page being posted and see what's get send.
User avatar
singo
User
User
Posts: 35
Joined: Mon Apr 23, 2007 4:50 am
Location: Nabiac NSW Australia

Help with ie.navigate and POST using PureDispHelper [Solved]

Post by singo »

Hi,

I couldn't solve this with only the navigate COM (I think because of the variant types), but I did get the result I wanted, with some more research.

This code sends a HTTP post request to a web page and shows the result in Internet Explorer.

Code: Select all

; based on FreeBASIC example
; changed to PB by ts-soft
; changed by Singo to post data to http page
; and view the result in Internet Explorer

EnableExplicit

Define.l ieApp, ieBusy
Define.s url, ieBody

dhToggleExceptions(#True)

ieApp = dhCreateObject("InternetExplorer.Application")

If ieApp

;create the form with data to post
;
; Remove the prompts ie Name: and change the type to hidden so that data is not shown
; you can also get rid of the <br>
;
  ieBody = "<form name=frm id=frm method=post action='http://10.0.0.155/feedback.php'>"
  ieBody + "Name: <input type=text name=name value='Singo'><br>"
  ieBody + "Email: <input type=text name=email value='Singo@myhost.com.au'><br>"
  ieBody + "Message: <input type=text name=message value='Hi this is a mail message from Singo'><br>"
  ieBody + "<input type=submit name=submit value='Posting data to web page ... please wait'></form>"

;open a blank IE page
  url = "about:blank"
  dhCallMethod(ieApp, "Navigate(%T)", @url)
;wait until page opened  
  dhGetValue("%d", @ieBusy, ieApp, "Busy")
  While ieBusy
    dhGetValue("%d", @ieBusy, ieApp, "Busy")
    Delay(100)
  Wend
;insert form to post
  dhPutValue (ieApp, "Document.body.innerHTML=%s",@ieBody)
;click the submit button
  dhCallMethod(ieApp,"Document.all.item(%s).click",@"submit")
;show the page
  dhPutValue (ieApp, "Visible = %b", #True)
  dhReleaseObject(ieApp) : ieApp = 0
  
EndIf
:D
Post Reply