Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从url字符串获取html响应?(计划/球拍)_Html_Url_Scheme_Racket - Fatal编程技术网

如何从url字符串获取html响应?(计划/球拍)

如何从url字符串获取html响应?(计划/球拍),html,url,scheme,racket,Html,Url,Scheme,Racket,如何从url字符串获取html响应?使用此选项: #lang racket (require net/url) (require net/websocket/client) (define google (string->url "http://google.com")) (ws-connect(struct-copy url google [scheme "ws"])) 给我ws-connect:无效的服务器握手响应。预期为#“\242\266\336\364\360\”\21~Y\

如何从url字符串获取html响应?使用此选项:

#lang racket
(require net/url)
(require net/websocket/client)
(define google (string->url "http://google.com"))

(ws-connect(struct-copy url google [scheme "ws"]))

给我
ws-connect:无效的服务器握手响应。预期为#“\242\266\336\364\360\”\21~Y\347w\21L\2326\”,得到#“\n”

我假设您只想做与HTTP GET等效的操作

(require net/url)
(define google (string->url "http://google.com"))
用于执行HTTP GET;它返回一个输入端口。此外,上面的URL会重定向,因此我们必须启用以下重定向

(define in (get-pure-port google #:redirections 5))
如果希望将响应作为单个字符串,可以使用:

或者您可以将其传递给某个函数,该函数将其解析为HTML或XML。网上有几个这样的图书馆;我推荐

另请参见,它会自动处理关闭端口的操作。

可能重复的
(define response-string (port->string in))
(close-input-port in)