Page 1 of 1

phpBB Login Scripz using "MSXML2.ServerXMLHTTP" ?

Posted: Sat Jun 24, 2023 9:26 am
by AUGE_OHR
hi,

my phpBB Forum "Reader" use "MSXML2.ServerXMLHTTP" to download Message of phpBB Forum

now there are some Forum where i need to login ( to get a Session-ID ? ) but how :?:
can somebody help me please

Re: phpBB Login Scripz using "MSXML2.ServerXMLHTTP" ?

Posted: Mon Jun 26, 2023 7:09 am
by edk
I think the Session-ID should be returned in the response header, but I'm not sure about that.
Check what headers you get in response to request.
After the send() method, you can read the response headers using the getAllResponseHeaders() method.

In response headers you should have set-cookie sequences, one of them contains sid (Session-ID), e.g.:
set-cookie: phpbb3_1234_sid=2f3d4881de6cc34e8ac9b05a02b55809; expires=Tue, 25-Jun-2024 09:29:28 GMT; path=/; domain=hmgforum.com; secure; HttpOnly

You read all cookies and in the next request you send these cookies in the header, e.g.:

Code: Select all

ohttp:Send()

cResponseHeaders := ohttp:getAllResponseHeaders()
     
//get cookies
cCookie := ""
FOR EACH cHeader IN hb_ATokens( cResponseHeaders, .T. )	
	IF Lower( Left( cHeader, 12 ) ) == "set-cookie: "
		cCookie += IF (!EMPTY( cCookie ), '; ', '') + hb_ATokens(SubStr( cHeader, 13 ), ';') [1]
	ENDIF
NEXT
	
(...)     
	
//next request -> set cookies

IF !Empty( cCookie )
	ohttp:setRequestHeader("Cookie", cCookie)	//required if exist
ENDIF

Re: phpBB Login Scripz using "MSXML2.ServerXMLHTTP" ?

Posted: Tue Jun 27, 2023 3:13 am
by AUGE_OHR
hi Edward,

thx for Answer.

i have "read" what you say ... but i´m a Internet "Dummy" so i do not understand how to use it

i use this CODE to download Message from phpBB Forum

cURL := https://www.hmgforum.com/viewtopic.php?t=
cFile := any Filename to hold Message
nThreadNo := 7451

Code: Select all

FUNCTION DownloadFromWWW( cURL, cFile, nThreadNo )
LOCAL oError, nTry, nStatus, nReadystate, cText, nPosi
LOCAL bOldError := ERRORBLOCK( { | e | BREAK( e ) } )
LOCAL oHttp     := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" )
LOCAL aStatus   := HttpStatusArray()
LOCAL aArray, x1

   IF FILE( cFile )
      hb_FileDelete( cFile )
   ENDIF

   IF .NOT. "http" $ cUrl
      oHttp := NIL
      RETURN .F.
   ENDIF

   BEGIN SEQUENCE                                                     // WITH { | oError | BREAK( oError ) }
      oHttp:Open( "GET", cUrl, .F. )
      // oHttp:setRequestHeader( "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0" )
      oHttp:setRequestHeader( "Content-Type", "text/xml; charset=utf-8" )

      nTry := 0
      DO WHILE EMPTY( oHTTP:readyState )                              // = 0
         nTry ++
         millisec( 500 )
         DO Events
         IF nTry > 5
            BREAK
         ENDIF
      ENDDO

      // oHttp:setRequestHeader( "Content-Type", "text/xml; charset=utf-8")
      oHttp:Send()

      nReadystate := oHttp:readyState
      IF nReadystate <> 4
         BREAK
      ENDIF

      nStatus := oHttp:Status
      IF nStatus = 200
         StrFile( oHttp:ResponseBody(), cFile )
         x1 := hb_jsonDecode( oHttp:ResponseBody(), @aArray )

      ELSEIF nStatus = 500
         lBreak := .T.
         cText := "Error Thread No. : " + VAR2CHAR( nThreadNo ) + CRLF + cText
         MessageBoxTimeout( cText, "nStatus =  " + VAR2CHAR( nStatus ), MB_ICONERROR, 3000 )
         lShowOnce := .F.
         BREAK

      ELSE
         Ondummy( oHttp:Status )
         nPosi := ASCAN( aStatus, { | x | x[ 1 ] = nStatus } )
         IF nPosi > 0
            cText := aStatus[ nPosi ] [ 2 ]
            Ondummy( TIME(), cText )
            //             lBreak := .T.
            //             lShowOnce := .T.
            //             BREAK
         ENDIF
      ENDIF

   RECOVER USING oError
      ERRORBLOCK( bOldError )

      IF EMPTY( nReadystate )
      ELSE
         lBreak := .T.
         lShowOnce := .T.
      ENDIF

      Ondummy( TIME(), oError:description, oError:operation, HB_VALTOSTR( oError:osCode ), "Error download " + cUrl )
      cText := hb_Translate( oError:Description, cTranslateCP + "WIN" )
      SayBarText( cText, "ICOERROR" )

      IF lBreak = .F.
         cText := "Error Thread No. : " + VAR2CHAR( nThreadNo ) + CRLF + cText
         MessageBoxTimeout( cText, "readyState " + VAR2CHAR( nReadystate ), MB_ICONERROR, 3000 )
         lShowOnce := .F.
      ENDIF

      IF lShowOnce = .T.
         lShowOnce := .F.
         MsgStop( "Error : " + cText, "readyState " + VAR2CHAR( nReadystate ) )
      ENDIF

      AADD( aError, { "Error Thread No. : " + VAR2CHAR( nThreadNo ), RECNO() } )

   END SEQUENCE

   ERRORBLOCK( bOldError )

   oHttp:Abort()
   oHttp := NIL

RETURN FILE( cFile )
i do NOT "login" yet so i can read only Public Message

i need to "login" to get Cookie / Session-ID which than is "add" ( sid= ) to URL String

Code: Select all

https://www.xbaseforum.de/search.php?search_id=active_topics&sid=f4f5f06a9330b2dc3ab692a5a6a597b5
so i need some "login" CODE before DownloadFromWWW() ... but how :?: