在rebol中使用Test-async-http.r时出错

时间:2010-06-19 16:22:37

标签: rebol

我试过

http://rebol.wik.is/Protocols/Test-async-http.r

do %async-protocol.r
do %async-http.r

buffer: copy ""
content-length: 0

handler: func [port [port!] event [error! word!]
] [ 
    switch event [
        connect [print "Connected." false]
        read [
            if port/sub-port/state/inbuffer [
                statustxt/text: form length? port/sub-port/state/inbuffer
                show statustxt
                if zero? content-length [
                    either parse/all port/sub-port/state/inbuffer [ thru "content-length: " copy content-length to newline to end ][
                        if content-length [
                            content-length: to-integer trim/all content-length
                        ]
                    ][ content-length: none ]
                ]
                if all [ content-length content-length > 0 ][
                    prog/data: ( to-integer statustxt/text ) / content-length       
                    show prog           
                ]       
            ]
            false
        ]
        write [false]
        close [print "Peer closed connection."  append buffer copy port 
            close port 
            write/binary last split-path to-url urlfld/text buffer 
            false ; if you use true here, you'll exit the View event handler as well
        ]
    ]
]

do-download: has [url link ][
    if not empty? url: urlfld/text [
        if parse/all url [ "http" opt "s" "://" to end][
            insert head url 'a
            link: open to-url url
            link/awake: :handler        
        ]
    ]
]


view/new center-face layout [
    across
    label "URL: " gold urlfld: field 300 return 
    prog: progress 340x15 return
    btn "Download" [ do-download ] return
    label "You can type while downloading" black return
    area 340x200 wrap
    at 160x50 statustxt: text "bytes" 100 white
]

wait []

我收到了这个错误:

** Access Error: Invalid port spec: ahttp://reboltutorial.com
** Where: do-download
** Near: link: open to-url url
link/awake:
>>

该代码中是否存在错误?

1 个答案:

答案 0 :(得分:1)

该错误消息表明您尚未安装async-http协议(http:// https://)

我刚试了一次,它适用于http://www.rebol.com