我想在Raspberry上运行的浏览器中从我的角度应用程序中调用Webiopi。由于Webiopi服务器不允许CORS请求,所以我已经使用apache创建了一个发送Header add "Access-Control-Allow-Origin" "*"头的代理。
这很好,但是对REST的调用会引发许多错误,主要是因为浏览器在CORS请求检查是否允许REST的情况下向服务器发送选项请求。但是webiopi处理程序根本不处理选项动词。
所以我开始自己写到代码中,没有python的经验。在python/webiopi/protocol/http.py文件中,我最后添加了:
def do_OPTIONS(self):
self.send_response(200,"ok")
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Methods", "POST,GET,OPTIONS")
self.send_header("Access-Control-Allow-Headers", "Authorization")
self.send_header("Access-Control-Allow-Headers", "Content-Type")
self.end_headers()现在它没有抛出任何错误,但是没有给我正确的响应我的GET请求。只是在选择之后就停止了。请求和响应如下:
请求头:
OPTIONS /GPIO/1/value HTTP/1.1
Host: localhost:8000
Connection: keep-alive
Access-Control-Request-Method: GET
Origin: http://192.168.1.108:51443
User-Agent: Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Raspbian Chromium/65.0.3325.181 Chrome/65.0.3325.181 Safari/537.36
Access-Control-Request-Headers: authorization
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: hu-HU,hu;q=0.9,en-US;q=0.8,en;q=0.7响应头:
HTTP/1.1 200 OK
Date: Fri, 23 Nov 2018 22:06:28 GMT
Server: WebIOPi/0.7.1/Python3.5
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST,GET,OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,OPTIONS
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked通用(来自铬网络选项卡):
Request URL: http://localhost:8000/GPIO/1/value
Request Method: OPTIONS
Status Code: 200 OK
Remote Address: [::1]:8000
Referrer Policy: no-referrer-when-downgrade我的索取请求在哪里?为什么我只看到那些我根本没有启动的选项?
来自request的请求:
this.http.get<number>(this.route+'GPIO/'+gpio+'/value').subscribe(result => {
resolve(result);
})发布于 2018-11-24 22:05:30
我必须将所有头都启用到http服务器:
def do_OPTIONS(self):
self.send_response(200,"ok")
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Methods", "*")
self.send_header("Access-Control-Allow-Headers", "*")
self.end_headers()https://stackoverflow.com/questions/53457074
复制相似问题