python代码:
response = HttpResponse(json.dumps(ret), content_type="application/json") response.__setitem__('Access-Control-Allow-origin', '*') response.__setitem__('Access-Control-Allow-Headers', 'x-requested-with,content-type')其他(php):
在被请求的Response header中加入
- // 指定允许其他域名访问
- header('Access-Control-Allow-Origin:*');
- // 响应类型
- header('Access-Control-Allow-Methods:POST');
- // 响应头设置
- header('Access-Control-Allow-Headers:x-requested-with,content-type');
本文介绍了如何在Python和PHP中实现跨域资源共享(CORS)的配置方法,通过设置HTTP响应头来允许不同源的资源请求,具体包括Access-Control-Allow-Origin、Access-Control-Allow-Methods和Access-Control-Allow-Headers等。
2387

被折叠的 条评论
为什么被折叠?



