⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f.class

📁 Gambas is a graphical development environment based on a Basic interpreter, like Visual Basic. It us
💻 CLASS
字号:
' Gambas class file'///////////////////////////////////////' Here we define a HttpClient object'///////////////////////////////////////'PRIVATE MyHTTP AS HttpClient'///////////////////////////////' This is a buffer I use when' a link is clicked (ugly hack:)'///////////////////////////////PRIVATE CurHost AS StringPUBLIC SUB Form_Open()  '///////////////////////////////////  ' We set Default configuration values  '///////////////////////////////////  ClsParams.ProxyHost="127.0.0.1:3128"  ClsParams.ProxyUser=""  ClsParams.ProxyPwd=""  ClsParams.ProxyAuth=Net.AuthNone  ClsParams.CookiesFile=System.Home & "/gbcookies.txt"  '////////////////////////////////////  ' Now we create the HttpClient object  '////////////////////////////////////  'MyHTTP=NEW HttpClient AS "MyHTTP" ENDPUBLIC SUB Button1_Click()  '/////////////////////////////////////////////////  ' When we press 'Get' button we start 'getting'  ' proccess  '/////////////////////////////////////////////////    '/////////////////////////////////////////////  ' If user has configured a proxy, we set  ' that values in HttpClient object  '/////////////////////////////////////////////  IF ClsParams.UseProxy AND ClsParams.ProxyHost<>"" THEN    '//////////////////////////////////    ' Host address and port     '//////////////////////////////////    MyHTTP.Proxy.Host=ClsParams.ProxyHost    MyHTTP.Proxy.Type=Net.ProxyHTTP    '//////////////////////////////////    ' If Proxy needs authentication,    ' we set it    '//////////////////////////////////    IF ClsParams.ProxyUser<>"" OR ClsParams.ProxyPwd<>"" THEN      MyHTTP.Proxy.User=ClsParams.ProxyUser      MyHTTP.Proxy.Password=ClsParams.ProxyPwd      MyHTTP.Proxy.Auth=ClsParams.ProxyAuth        ELSE      '///////////////////////////////////      ' No authentication needed      '///////////////////////////////////      MyHTTP.Proxy.Auth=Net.AuthNone    END IF  ELSE    '//////////////////////////////////////    ' No proxy selected (direct connection)     '//////////////////////////////////////    MyHTTP.Proxy.Host=""    ' todo authnone  END IF      '/////////////////////////////////////////////////  ' User and Password settings to access to that  ' document (this is a HTTP server authorization,  ' not a Proxy authorization)  '/////////////////////////////////////////////////  ' 1º User and password  IF ChkPassword.Value THEN    MyHTTP.User=TxtUser.Text     MyHTTP.Password=TxtPassword.Text    ' 2º Authorization type    SELECT CASE CmbAuth.Index      CASE 0        MyHTTP.Auth=Net.AuthBasic      CASE 1        MyHTTP.Auth=Net.AuthNTLM      CASE 2        MyHTTP.Auth=Net.AuthDigest      CASE 3        MyHTTP.Auth=Net.AuthGSSNEGOTIATE    END SELECT  ELSE    MyHTTP.User=""    MyHTTP.Auth=Net.AuthNone  END IF      '//////////////////////////////////  ' A bit of feedback for user...  '//////////////////////////////////  TextArea1.Text=""  TxtInfo.Text="Connecting..."  Navigator.Text=""    '////////////////////////////////////  ' URL to Get  '////////////////////////////////////   MyHTTP.Url=TxtHost.Text      '////////////////////////////////////  ' a little buffer for me  '////////////////////////////////////  CurHost=Mid(MyHTTP.Url,8)     '////////////////////////////////////  ' Cookies  '////////////////////////////////////  MyHTTP.CookiesFile=ClsParams.CookiesFile  MyHTTP.UpdateCookies=ClsParams.UpdateCookies    '////////////////////////////////////  ' Let's get it!  '////////////////////////////////////  PRINT MyHTTP.Proxy.Auth  MyHTTP.Get ()    '///////////////////////////////////////////  ' If we'd want to download remote document  ' to a file, instead of receving it in  ' memory, we could do that:  ' MyHTTP.Get( "FilePath" )  '///////////////////////////////////////////ENDPUBLIC SUB MyHTTP_Connect()    '///////////////////////////////////////////////  ' This event from HttpClient raises when   ' we connect successfully with remote server  ' and allows us to give more feed-back to user  '///////////////////////////////////////////////   TxtInfo.Text="Connected, waiting for reply..."  ENDPUBLIC SUB MyHTTP_Read()  '///////////////////////////////////////////  ' This event raises when a new piece of data  ' arrives to us from server, so we read that  ' part of the document  '///////////////////////////////////////////  DIM sBuf AS String  DIM MyLoop AS Integer  '/////////////////////////////////  ' more feedback...  '/////////////////////////////////  TxtInfo.Text="Receiving data..."    '/////////////////////////////////  ' Header of HTTP document received  ' from server  '/////////////////////////////////   IF TextArea1.Text="" THEN    FOR MyLoop=0 TO MyHTTP.Headers.Count-1      TextArea1.Text=TextArea1.Text & MyHTTP.Headers[MyLoop]    NEXT   END IF     '/////////////////////////////////  ' If really there's data to read,  ' we read it and place it in our  ' "navigator" screen  '//////////////////////////////////  IF Lof(MyHTTP) THEN     READ #MyHTTP,sBuf,Lof(MyHTTP)    Navigator.Text=Navigator.Text & sBuf  END IF  ENDPUBLIC SUB MyHTTP_Error()  '////////////////////////////  ' If something fails, this  ' event raises and connection  ' is stopped  '////////////////////////////   CurHost=""   TxtInfo.Text="Error " & MyHTTP.Status  ENDPUBLIC SUB MyHTTP_Finished()  '/////////////////////////////////////  ' When all document has been received,  ' this event raises  '/////////////////////////////////////  DIM sBuf AS String  DIM MyLoop AS Integer  '//////////////////////////////  ' feeback...  '//////////////////////////////  TxtInfo.Text="OK"  IF TextArea1.Text="" THEN    FOR MyLoop=0 TO MyHTTP.Headers.Count-1      TextArea1.Text=TextArea1.Text & MyHTTP.Headers[MyLoop]    NEXT   END IF    '///////////////////////////////////  ' we extract all possible data  ' buffered in HttpClient  '///////////////////////////////////  IF Lof(MyHTTP) THEN    READ #MyHTTP,sBuf,Lof(MyHTTP)    Navigator.Text=Navigator.Text & sBuf  END IF  ENDPUBLIC SUB mnuOptions_Click()  '////////////////////////////////////  ' If user wants to modify parameters  '////////////////////////////////////  FConfig.ShowModal  ENDPUBLIC SUB Form_Close()  '//////////////////////////////////////  ' When program finishes, we must ensure  ' that we close HttpClient object  '///////////////////////////////////////  MyHTTP.Stop()  ENDPUBLIC SUB BtnStop_Click()  '///////////////////////////////////////  ' If user wants to close the  ' connection...  '///////////////////////////////////////  IF MyHttp.Status > 0 THEN TxtInfo.Text="Cancelled by user"  MyHTTP.Stop()    ENDPUBLIC FUNCTION Correct_Url(sCad AS String) AS String    DIM MyLoop AS Integer    IF Instr(sCad,"://") THEN RETURN sCad    IF Left(sCad,1)="/" THEN    IF Instr(CurHost,"/") THEN  CurHost=Left(CurHost,Instr(CurHost,"/")-1)    RETURN CurHost & sCad  ELSE    IF Right(CurHost,1)="/" THEN RETURN CurHost & sCad    RETURN CurHost & "/" & sCad  END IF   ENDPUBLIC SUB Navigator_Link(Path AS String)   IF MyHTTP.Status>0 THEN MyHTTP.Stop()  TxtHost.Text=Correct_Url(Path)  Button1_Click()ENDPUBLIC SUB ChkPassword_Click()  IF ChkPassword.Value THEN    TxtUser.Enabled=TRUE    TxtPassword.Enabled=TRUE    CmbAuth.Enabled=TRUE  ELSE    TxtUser.Enabled=FALSE    TxtPassword.Enabled=FALSE    CmbAuth.Enabled=FALSE  END IFEND

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -