https POST

https POST

Postby Enrico Maria Giordano » Tue Jul 31, 2012 1:18 pm

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: https POST

Postby Enrico Maria Giordano » Tue Jul 31, 2012 2:03 pm

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: https POST

Postby Rick Lipkin » Tue Jul 31, 2012 3: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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: https POST

Postby Enrico Maria Giordano » Tue Jul 31, 2012 3:12 pm

Yes, I'm very interested, please. Anyway, now I have a problem: the following expression

Code: Select all  Expand view
oExp:Document:Body:InnerText


gives me an error:

Code: Select all  Expand view
Error InternetExplorer.Application:DOCUMENT/0  S_OK: BODY


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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: https POST

Postby Rick Lipkin » Tue Jul 31, 2012 4: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: Select all  Expand view


     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: Select all  Expand view

    //   cSubmit_Login_button := "document:forms:login: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: Select all  Expand view

//------------------------------
// this function takes a method string
// and evals it instead of creating a complex
// code block
//
//  OSendMulti( IE,"document:forms: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 )

 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: https POST

Postby Enrico Maria Giordano » Tue Jul 31, 2012 4:43 pm

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: https POST

Postby Lailton » Tue Jul 31, 2012 5:56 pm

Enrico,

Try, it's http more i think that work to https too.:
Code: Select all  Expand view
//--------------------------------------------------------------------------------------------------//
  #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: Select all  Expand view
<?php
 if($_POST){
  echo "Yes Post :-)\n\n";
  print_r( $_POST );
 }else{
  echo "Not Post :-(";
 }
?>


:)
Regards,
Lailton Fernando Mariano
User avatar
Lailton
 
Posts: 153
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil

Re: https POST

Postby Enrico Maria Giordano » Tue Jul 31, 2012 6:16 pm

Thank you, I will try it.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: https POST

Postby Enrico Maria Giordano » Tue Jul 31, 2012 6:54 pm

It worked! Many thanks! :-)

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: https POST

Postby Lailton » Tue Jul 31, 2012 7:16 pm

:D Nice !
Regards,
Lailton Fernando Mariano
User avatar
Lailton
 
Posts: 153
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil

Re: https POST

Postby Rick Lipkin » Tue Jul 31, 2012 9:35 pm

Enrico

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

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: https POST

Postby Enrico Maria Giordano » Tue Jul 31, 2012 10:35 pm

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 76 guests