Home aSocks Sample File: HTTP/HTTPRequestCRT.prg
Sample Application Files
Encode:
  • Encode.prg
  • Finger:
  • Finger.prg
  • HTTP:
  • HTTPGrabContentGUI.prg
  • HTTPHeaderCRT.prg
  • HTTPHeaderGUI.prg
  • HTTPLinkListCRT.prg
  • HTTPRequestCRT.prg
  • SSL_POST.prg
  • RawWrite.prg
  • MIME:
  • MIME_Dlg.prg
  • NNTP:
  • NewsCheckCRT.prg
  • NewsCheckGUI.prg
  • SMTP:
  • CommandLineMailer.prg
  • SendMail.prg
  • SendMailGUI.prg
  • Telnet:
  • TelnetDemo.prg
  • TelnetGUI.prg
  • Time:
  • GrabTime.prg
  • TimeZoneCRT.prg
  • TimeZoneGUI.prg
  • WhoIs:
  • WhoIs.prg
  • //********************************************************
    //   Project: HTTP Sample for aSocks Library - CRT Version
    //********************************************************
    //    Author: Michael Mc Vicker
    // Copyright: © 01/19/01 - All Rights Reserved
    //  FileName: HTTPRequestCRT.PRG
    //********************************************************
    //
    // aSocks Sample Application:
    //    Sample application to demonstrate the functionallity
    //    of the aSocks TCP/IP Library.
    //
    //  Components:
    //    HTTP Class
    //
    // Updates:
    //  Last Update: 01/20/01 by MMM
    //
    // Notes:
    //
    //********************************************************
    
    
    // SocketTools License Key
    #Include "CSKeys.ch"
    #Include "AsocksKey.ch"
    #Include "aSocksConst.ch"
    #Include "aSocksError.ch"
    
    //*******************************
    Procedure DBESys ( )
    //** Stop Requiremnet of Database DLLs ***
    Return
    
    
    Procedure Main()
      Local oHTTP, nKey := 0, cHost := space(50)
      oHTTP := aprHTTP():New(ASOCKS_LICENSE_KEY,CSTOOLS_LICENSE_KEY)
      // Make sure ::Debug Display is OFF
      oHTTP:Debug := .F.
      oHTTP:Trace(.T.,"HTTPREQUEST.log",TRACE_HEXDUMP)
      // Display Column Titles
      @ 0, 0 say "[Space] List Headers"
      @ 2, 0 say "HTTP Header for :"+cHost
      @ 3, 0 say "===================================="
      @ 22,29 say "Press [Escape] to Quit."
      Do While nKey != 27  // [Esc]
        nKey := Inkey( 0 )
        If nKey = 32       // [Space]
          @ 4,0 Clear to 21,79
          @ 1, 0 say "Enter Host Name: " Get cHost Picture "@K"
          Read
          @ 2, 0 say "HTTP Header for :"+Trim(cHost)
          GetURL( oHTTP, trim(cHost) )
        EndIF
        If nKey = -4       // [F5]
          @ 4,0 Clear to 21,79
          @ 1, 0 say "Enter Host Name: " Get cHost Picture "@K"
          Read
          @ 2, 0 say "HTTP Header for :"+Trim(cHost)
          GetURL( oHTTP, trim(cHost) )
        EndIF
      Enddo
    Return
    
    //*******************************
    Function  GetURL ( oHTTP, cServer)
    //*******************************
      Local cURL, cWebPage, nPort := IPPORT_HTTP, nTimeout := 5, nParams := HTTP_OPTION_NONE
        cURL := cServer
        If At("/",cURL) > 0
          cServer := Substr(cServer,1,at("/",cServer)-1)
        EndIF
        cURL := StrTran(cURL,cServer,"")
        If At(".",cURL) = 0
          If len(cURL) > 0
            If substr(cURL,len(cURL),1) = "/"
              cURL := cURL
            Else
              cURL := cURL+"/index.htm"  // Default a Web Page to retrieve
            EndIF
          Else
            cURL := cURL+"/index.htm"  // Default a Web Page to retrieve
          EndIF
        EndIF
        if oHTTP:Connect(cServer,nPort,nTimeOut,nParams) > 0
          cWebPage := oHTTP:SendRequest(HTTP_COMMAND_HEAD,cURL)
          If cWebPage = NIL
            aprMsg("Could not connect to Requested Resource","Link List Error:")
          Else
            aprMsg(cWebPage)
          EndIF
        Else
          aprMsg("Connection Error: "+cServer,"HTTP Status:")
        endif
    Return (.T.)
    
    //*******************************
    Procedure WriteResults ( cResults, nOffset )
    //*******************************
      Local x := 0
      nOffset := IIf(ValType(nOffset) != "N", 0, nOffset)
      @ (4+nOffset)-1, 0 say ""
      For x = 1 To MLCount(cResults, 79)
        ? StrTran(memoline(cResults,79,x),CR_LF,"")
        If (x%20) = 0
          wait "Press any key to continue"
        EndIF
      Next
      wait "Press any key to continue"
      @ 0, 0 Clear
      @ 0, 0 say "[Space] List Headers"
      @ 2, 0 say "HTTP Header for :"
      @ 3, 0 say "===================================="
      @ 22,29 say "Press [Escape] to Quit."
    Return