ionic和python服务器中的http post

ionic和python服务器中的http post,python,json,ionic-framework,http-post,Python,Json,Ionic Framework,Http Post,我使用python json http服务器,需要在该服务器中使用带有离子的post json,但是http post方法发送选项类型。我需要发送post类型。有什么问题吗 服务器: def do_POST(self): content_len = int(self.headers.getheader('content-length')) post_body = self.rfile.read(content_len) self.send_response(200)

我使用python json http服务器,需要在该服务器中使用带有离子的post json,但是http post方法发送选项类型。我需要发送post类型。有什么问题吗

服务器:

def do_POST(self):
    content_len = int(self.headers.getheader('content-length'))
    post_body = self.rfile.read(content_len)
    self.send_response(200)
    self.end_headers()

    data = json.loads(post_body)

    self.wfile.write(data['id'])
    return
ionic http post方法:

$http.post(url, JSON.stringify({"id":"1"})).success(function (res) {
            console.log("res" + res);
        }).error(function (data, status, headers, config) {
            console.log(data, status, headers,JSON.stringify (config));
        });
来自python服务器的错误:

192.168.1.4 - - [10/Mar/2017 02:36:28] code 501, message Unsupported method ('OPTIONS')
192.168.1.4 - - [10/Mar/2017 02:36:28] "OPTIONS / HTTP/1.1" 501 -

这看起来像是一个跨源资源共享(CORS)飞行前请求问题

我建议在类中添加一个do_OPTIONS方法:

def do_OPTIONS(self):           
    self.send_response(200, "ok")       
    self.send_header('Access-Control-Allow-Origin', '*')                
    self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
    self.send_header("Access-Control-Allow-Headers", "X-Requested-With")
这将告诉浏览器POST请求具有访问控制

另一篇关于这方面的好文章可以找到