Rebol [
    file: %so-chat.r3
    author: "Graham"
    date: 16-Feb-2013
    purpose: {post messages into the Rebol-red chat room on Stackoverflow}
    Notes: {You'll need to capture your own cookie and fkey using wireshark or similar.}
]
bot-cookie: {multiple cookies here}

bot-fkey: "string-found-at-end-of-each-message"

url-encode: func [
    "URL-encode a string" 
    data "String to encode" 
    /local new-data
] [
    new-data: make string! "" 
    normal-char: charset [
        #"A" - #"Z" #"a" - #"z" 
        #"." #"*" #"-" #"_" 
        #"0" - #"9"
    ] 
    if not string? data [return new-data] 
    forall data [
        append new-data either find normal-char first data [
            first data
        ] [
            join "%" copy/part tail to string! to-hex to integer! first data -2
        ]
    ] 
    new-data
] 

target-url: http://chat.stackoverflow.com/chats/291/messages/new

chat: func [ message ][
    result: to string! write target-url bot-header: compose/deep copy/deep [
        POST
        [ 
            Host: "chat.stackoverflow.com"
            Origin: "http://chat.stackoverflow.com"
            Accept: "application/json, text/javascript, */*; q=0.01"
            X-Requested-With: "XMLHttpRequest"
            Referer: "http://chat.stackoverflow.com/rooms/291/rebol-and-red"
            Accept-Encoding: "gzip,deflate"
            Accept-Language: "en-US"
            Accept-Charset: "ISO-8859-1,utf-8;q=0.7,*;q=0.3"
            Content-Type: "application/x-www-form-urlencoded"
            cookie: (bot-cookie)
        ]
        (rejoin [ "text=" url-encode message "&fkey=" bot-fkey ])
    ]   
    ?? result
]

halt