Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

get header only from http web server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • get header only from http web server

    retrieve the header only from a http web server

    Code:
    'compile with pbcc 4.03 or 4.04
    'webhead.bas
    #COMPILE EXE
    DEFLNG a-z
    
    FUNCTION PBMAIN()
    serverlocation$=LCASE$(TRIM$(COMMAND$))
    IF LEN(serverlocation$)>1 THEN
        IF RIGHT$(serverlocation$,1)="/" THEN serverlocation$=LEFT$(serverlocation$,(LEN(serverlocation$)-1))
    END IF
       
        serverport = 80                     'Port (should be 80)
        fileURL$ = "http://"+serverlocation$            'Filename to grab
    
        TCP OPEN PORT serverport AT serverlocation$ AS #1 TIMEOUT 15000    'Open server
        PRINT
        PRINT   "requesting http header from"
        PRINT FILEURL$
        IF ISFALSE(CONSOUT) THEN STDOUT "requesting http header from"
        IF ISFALSE(CONSOUT) THEN STDOUT fileurl$
        
        TCP PRINT #1, "HEAD " + FILEURL$+ " HTTP/1.0"
        TCP PRINT #1, "Host: " + serverlocation$
        TCP PRINT #1, ""
    
    
        buffer$=SPACE$(4096)                            'Download file
        received$=""
        IF ERR THEN
           PRINT "server not found"
            IF ISFALSE(CONSOUT) THEN STDOUT "server not found"
           EXIT FUNCTION
        END IF
    
        DO
            TCP RECV #1, 4096, buffer$      'Download 4k block
            IF buffer$ = "" THEN EXIT DO    'Done?
            received$ = received$ & buffer$ 'Append to total file buffer
        LOOP
    
        TCP CLOSE #1                        'Disconnect from server
        PRINT  "server found"
        IF ISFALSE(CONSOUT) THEN STDOUT "server found"
        
    received$=TRIM$(received$)
    STDOUT  $CRLF+received$
     IF ISFALSE(CONSOUT) THEN PRINT:PRINT "see redirected output for http header information"
    
    END FUNCTION
    you can get the exe "webhead.exe" for a short time from today at
    http://pdptemp.dyndns.org/zipcode/
    Last edited by Paul Purvis; 28 Nov 2007, 12:41 AM.
    p purvis

  • #2
    change of code

    changed 1 line of code
    from
    TCP PRINT #1, "HEAD " + FILEURL$+ " HTTP/1.1"
    to
    TCP PRINT #1, "HEAD " + FILEURL$+ " HTTP/1.0"

    sorry
    the program is much faster now.
    p purvis

    Comment

    Working...
    X