[futurebasic] Re: HTTP encoder?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 1998 : Group Archive : Group : All Groups

From: tatewake@... (Terence Jordan)
Date: Wed, 1 Apr 1998 20:32:27 -0500
>I have a program I have to write that should encode data in HTTP format. I
>would like to write this app in FB, but I can write it in C if I have to.
>
>Now, for the punch-line. Do any of you know of any functions that will do
>this encoding for me? (C links would be fine as well... I just need the
>code... 8) )
>
>Thanks a bunch,
>-Wilcox
>
>Second post in as many minutes.

Here's where I come in...

The easiest way is to trap all non alpha-numeric characters(except maybe
the slash:)
And everything is encoded into hexadecimal, just use a "%" instead of an
"&H", so here's your program... keep in mind that I'm not following the
spec exactly, this is more of a "safe way". You can find the RFC(request
for comments) form on the internet if you reallllly need to conform to the
spec. (Nothing will break, in other words.):

COMPILE 0,_caseInsensitive

beginning$ = "http://"
http$=""
myfile$ = FILES$(_fOpen,,,Vref%)
LONG IF myfile$<>""
  http$=beginning$
  FOR ex& = 1 TO LEN(myfile$)
    es$ = MID$(myfile$,ex&,1)
    et$ = UCASE$(es$)
    LONG IF et$<"A" OR et$>"Z"
      LONG IF et$<"0" OR et$>"9"
        SELECT CASE et$
          CASE "-","!","$","^","*","(",")"
            http$=http$+es$
          CASE ",",".",";"
            http$=http$+es$
          CASE "'",CHR$(34)
            http$=http$+es$
          CASE ELSE
            hx$ = "00" + HEX$(ASC(es$))
            hx$ = RIGHT$(hx$,2)
            http$ = http$ + "%" + hx$
        END SELECT
      XELSE
        http$=http$+es$
      END IF
    XELSE
      http$=http$+es$
    END IF
  NEXT ex&
END IF

WINDOW #1,"httptext",(0,0)-(320,200)
PRINT http$
DO
  HANDLEEVENTS
UNTIL FN BUTTON
FLUSHEVENTS
END

...HTH



-- Terence Jordan (tatewake@...)
Inspired Software. http://inspired.netstreet.net/
Macintosh, Dos, Windows, and BeOS software solutions.
Phone: 407-728-7563
....................................
.MacSloMo: 6502 emulation,         .
.the first CPU Emu in FB!          .
.Source code is available!         .
.http://inspired.netstreet.net/POC/.
....................................