我想要一个词
read-site ( add n buff max -- n flag )其中'add n‘是站点名缓冲区,'buff max’是应该将ASCII文本读入的缓冲区,'n‘是已读取的字节数,如果操作成功,flag为真。
在Linux、Android或Windows中,这是可能的吗?
发布于 2018-02-02 22:26:40
只是一系列的方法
最简单的正确方法应该是在Forth (如果有的话)中使用库(或绑定)。Gforth存储库中似乎存在某种类似的库--参见netlib/httpclient.fs。显然,它不适用于HTTPS。
下一种方法是使用适当的外部共享库,例如https://curl.haxx.se/libcurl/。它是一个众所周知的工具,它支持许多协议(绑定和一些使用示例也可以在supports中找到)。
下一种方法是使用系统调用并生成子进程(在资源使用方面不太有效)。葛弗斯有system这个词。用法示例:
S" curl http://example.com/" system网页HTML代码将被打印到stdout。不幸的是,在这种情况下,使用outfile-execute重定向不起作用(它看起来像是system word的不完整或弱实现)。
因此,应该使用临时文件:
S" curl --silent http://example.com/ > tmp" system之后,可以将文件内容读入给定的缓冲区。
概念上的实施如下:
: read-url ( d-buffer d-txt-url -- d-txt-webpage )
s" curl --silent {} > tmp" interpolate system
over >r \ keep buf addr
s" tmp" open-file throw dup >r read-file throw
r> close-file throw
r> swap
;其中,interpolate ( i*x d-txt1 -- d-txt2 )扩展给定的模板。
https://stackoverflow.com/questions/48587263
复制相似问题