FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour https POST
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
https POST
Posted: Tue Jul 31, 2012 01:18 PM

Dear friends, I need to send an https POST (data and headers) using xHarbour/FWH. Any ideas?

EMG

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: https POST
Posted: Tue Jul 31, 2012 02:03 PM

Never mind. Found in an old thread! :-)

EMG

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: https POST
Posted: Tue Jul 31, 2012 03:05 PM

Enrico

I have done quite a bit of IE ( internet explorer ) automation .. I was thinking about sharing that with you .. but I didn't know if you wanted to go there.

Just curious about your solution?

Thanks
Rick Lipkin

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: https POST
Posted: Tue Jul 31, 2012 03:12 PM
Yes, I'm very interested, please. Anyway, now I have a problem: the following expression

Code (fw): Select all Collapse
oExp:Document:Body:InnerText


gives me an error:

Code (fw): Select all Collapse
Error InternetExplorer.Application:DOCUMENT/0  S_OK: BODY


and I don't know why... :-)

EMG
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: https POST
Posted: Tue Jul 31, 2012 04:38 PM
Enrico

I built a webcrawling engine that went out to various Inventory vendor sites and with IE automation, I started IE, logged into a site, inserted text into the sites search and interrogated the results.

When 'scraping the page' .. I found what I was looking for was the Outertext, not the InnerText .. here is a snipit of the code .. notice the 5th line.

Lots more to share if I can help!

Rick Lipkin

Code (fw): Select all Collapse
     cSAY := "Gathering product information "
     oSay:ReFresh()
     SysReFresh()

     try
        cTEXT := lower(IE1:document:documentElement:outerTEXT)
     catch
        cSAY := "Can not open Product information "+cPARTS
        oSay:ReFresh()
        SysReFresh()

        try
           IE1:Quit()
        catch
        end try

        IE1 := NIL
        SysReFresh()

        return(.f.)
     end try

     SysWait( 3)

     // take out all the control char

     nLOOP := 0
     DO WHILE .T.
        IF AT( (chr(13)+chr(10)), cTEXT )  > 0
          cTEXT := STRTRAN( cTEXT, (chr(13)+chr(10)), space(1) )
        ENDIF
        nLOOP++
        IF nLOOP > 500
           EXIT
        ENDIF
     ENDDO

  *   msginfo( ctext )


I found poking around on websites works best when you know the exact DOM elements distinguished location .. here is an example of clicking on a login button. Notice the code block .. Rao helped me consolidate the Code block into a more readable function that even handles "-" hyphens and spaces in the DOM address that typically will not pass as parameters.

Code (fw): Select all Collapse
    //   cSubmit_Login_button := "document:login" // actual DOM address 

   try
   *   bSUBMIT := &( [ { | IE | IE:]+cSUBMIT_LOGIN_BUTTON_DOM+[:Click()]+[ }] )
      OSendMulti( IE, cSUBMIT_LOGIN_DOM+":Click",   )    // in func_lib.prg
   catch
      cSAY := "Clicking Login button  FAILED"
      oSay:ReFresh()
      SysReFresh()

      aLINE := { cURL,cPARTS,cSAY,"   ", "    ", "  " }
      AAdd( aResults, aLine )
      oLbx2:Refresh()
      oLbx2:GoBottom()

      try
         IE:Quit()
      catch
      end try

      IF cTESTING = "TEST"
         oBtn1:Enable()
         oBtn2:Enable()
      ENDIF

      SysReFresh()
      RETURN(.F.)
   end try


oSendMulti() Function

Code (fw): Select all Collapse
//------------------------------
// this function takes a method string
// and evals it instead of creating a complex
// code block
//
//  OSendMulti( IE,"document:tsf:lst-ib:Value", cPARTS )
//
//-----------------------------------------
Function OSendMulti( o, cMsg, uVal )

   local aMsg  := HB_ATokens( cMsg, ":" )
   local n     := Len( aMsg ) - If( uVal == nil, 0, 1 )
   local p

   AEval( aMsg, { |c| o := OSendEx( o, c ) }, 1, n )
   if uVal != nil
      o        := OSend( o, "_" + ATail( aMsg ), uVal )
   endif

return( o )
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: https POST
Posted: Tue Jul 31, 2012 04:43 PM

Unfortunately, my problem is with Body not with InnerText. I cannot understand why the Body property is not accessible...

EMG

Posts: 231
Joined: Fri Jul 20, 2012 01:49 AM
Re: https POST
Posted: Tue Jul 31, 2012 05:56 PM
Enrico,

Try, it's http more i think that work to https too.:
Code (fw): Select all Collapse
//--------------------------------------------------------------------------------------------------//
  #include "FiveWin.ch"
//--------------------------------------------------------------------------------------------------//
  Function Main()
   MsgInfo( SendPostToUrl( "http://localhost/test.php", "name=lailton&country=brazil" ), "POST" )
  Return Nil
//--------------------------------------------------------------------------------------------------//
  Function SendPostToUrl( cUrl, cParams )
   Local oOle,cRet:='',uRet
    Try
     oOle := CreateObject( 'MSXML2.XMLHTTP' )
    Catch
     oOle := CreateObject( 'Microsoft.XMLHTTP' )
    End
    oOle:Open( 'POST', cUrl, .f. )
    oOle:SetRequestHeader( "Content-Type", "application/x-www-form-urlencoded" )
    oOle:Send( cParams )
    SysRefresh()
    #ifdef __XHARBOUR__
     cRet := oOle:ResponseBody
    #else
     AEval(oOle:ResponseBody,{|uRet|cRet+=Chr(uRet)})
    #endif 
  Return cRet
//--------------------------------------------------------------------------------------------------//


test.php
Code (fw): Select all Collapse
<?php
 if($_POST){
  echo "Yes Post :-)\n\n";
  print_r( $_POST );
 }else{
  echo "Not Post :-(";
 }
?>


:-)
Regards,

Lailton Fernando Mariano
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: https POST
Posted: Tue Jul 31, 2012 06:16 PM

Thank you, I will try it.

EMG

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: https POST
Posted: Tue Jul 31, 2012 06:54 PM

It worked! Many thanks! :-)

EMG

Posts: 231
Joined: Fri Jul 20, 2012 01:49 AM
Re: https POST
Posted: Tue Jul 31, 2012 07:16 PM

Nice !

:D

Regards,

Lailton Fernando Mariano
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: https POST
Posted: Tue Jul 31, 2012 09:35 PM

Enrico

Just curious .. I looked at Lawton's code .. I do not understand what you are trying to do ??

Thanks
Rick Lipkin

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: https POST
Posted: Tue Jul 31, 2012 10:35 PM

I need to send a POST via https with custom headers and data.

EMG

Continue the discussion