设置跨域资源共享
Last updated
2023-08-17 17:15:43
{"value":"### **\u8bbe\u7f6e\u8de8\u57df\u8d44\u6e90\u5171\u4eab**\n\n\u70b9\u51fb\u300c\u9ad8\u7ea7\u8bbe\u7f6e\u300d-\u300c\u7f13\u5b58\u914d\u7f6e\u300d-\u300c\u4fee\u6539\u914d\u7f6e\u300d\uff0c\u5373\u53ef\u4fee\u6539\u8de8\u57df\u8bbe\u7f6e\u3002\n\n![](https:\/\/tp2lravq.hk03.1112oss.com\/20230817162101qc3r3cqj7u1t7k63afvn5ll5mo27go70.png) \n\n- \u8de8\u57df\u8bbf\u95ee\u5373\u901a\u8fc7 HTTP \u8bf7\u6c42\uff0c\u4ece\u4e00\u4e2a\u57df\u53bb\u8bf7\u6c42\u53e6\u4e00\u4e2a\u57df\u7684\u8d44\u6e90\u3002\u53ea\u8981\u534f\u8bae\u3001\u57df\u540d\u3001\u7aef\u53e3\u6709\u4efb\u4f55\u4e00\u4e2a\u4e0d\u76f8\u540c\uff0c\u90fd\u4f1a\u88ab\u5f53\u4f5c\u662f\u4e0d\u540c\u7684\u57df\u3002\u8de8\u57df\u8d44\u6e90\u5171\u4eab CORS\uff08Cross-Origin Resource Sharing\uff09\uff0c\u662f HTML5 \u63d0\u4f9b\u7684\u6807\u51c6\u8de8\u57df\u89e3\u51b3\u65b9\u6848\u3002\n- \u9ed8\u8ba4\u652f\u6301 CORS \u6807\u51c6\u6765\u5b9e\u73b0\u8de8\u57df\u8bbf\u95ee\uff0c\u5e76\u63d0\u4f9b\u4e86\u5b58\u50a8\u7a7a\u95f4\uff08Bucket\uff09\u7ea7\u522b\u7684 CORS \u81ea\u5b9a\u4e49\u89c4\u5219\u914d\u7f6e\uff0c\u6dfb\u52a0\u89c4\u5219\u540e\u5b58\u50a8\u4f1a\u6839\u636e\u5df2\u8bbe\u5b9a\u7684\u89c4\u5219\u6765\u5141\u8bb8\u6216\u8005\u62d2\u7edd\u76f8\u5e94\u7684\u8de8\u57df\u8bf7\u6c42\u3002\n- \u7528\u6237\u53ef\u5bf9\u7a7a\u95f4\u8fdb\u884c\u8bbe\u7f6e\u5e76\u5bf9\u7a7a\u95f4\u4e2d\u7684\u5bf9\u8c61\uff08Object\uff09\u8fdb\u884c\u8de8\u57df\u8bbf\u95ee\u3002\n- \u5f53\u6536\u5230\u4e00\u4e2a\u8de8\u57df\u8bf7\u6c42\uff08\u6216\u8005 OPTIONS \u8bf7\u6c42\uff09\u65f6\uff0c\u4f1a\u8bfb\u53d6\u5b58\u50a8\u7a7a\u95f4\u5bf9\u5e94\u7684 CORS \u89c4\u5219\uff0c\u7136\u540e\u8fdb\u884c\u76f8\u5e94\u7684\u6743\u9650\u68c0\u67e5\u3002\u7cfb\u7edf\u4f1a\u4f9d\u6b21\u68c0\u67e5\u6bcf\u4e00\u6761\u89c4\u5219\uff0c\u4f7f\u7528\u7b2c\u4e00\u6761\u5339\u914d\u7684\u89c4\u5219\u6765\u5141\u8bb8\u8bf7\u6c42\u5e76\u8fd4\u56de\u5bf9\u5e94\u7684 header\u3002\u5982\u679c\u6240\u6709\u89c4\u5219\u90fd\u5339\u914d\u5931\u8d25\uff0c\u5219\u4e0d\u9644\u52a0\u4efb\u4f55 CORS \u76f8\u5173\u7684 header\u3002\n\n\n\n#### **\u521b\u5efa\u89c4\u5219**\n\n\u70b9\u51fb\u300c\u521b\u5efa\u89c4\u5219\u300d\u6309\u94ae\uff0c\u5f39\u51fa\u89c4\u5219\u521b\u5efa\u6846\u5982\u4e0b\uff1a\n\n![](https:\/\/tp2lravq.hk03.1112oss.com\/20230817171255e7towv4f3a8h3sdlbw6qp2erk5ga8duq.png)\n\n\u586b\u5199\u6765\u6e90\uff1a\u6307\u5b9a\u5141\u8bb8\u7684\u8de8\u57df\u8bf7\u6c42\u7684\u6765\u6e90\n\n- \u5fc5\u586b\n- \u5141\u8bb8\u591a\u6761\u5339\u914d\u89c4\u5219\uff0c\u591a\u6761\u89c4\u5219\u9700\u6362\u884c\u586b\u5199\n- \u6bcf\u6761\u5339\u914d\u89c4\u5219\u5141\u8bb8\u4f7f\u7528\u6700\u591a\u4e00\u4e2a\u661f\u53f7*\u901a\u914d\u7b26\n- \u5355\u72ec\u586b\u5199\u661f\u53f7*\u901a\u914d\u7b26\uff0c\u8868\u793a\u5141\u8bb8\u6240\u6709\u6765\u6e90\u7684\u8de8\u57df\u8bf7\u6c42\n\n\u586b\u5199\u5141\u8bb8Methods\uff1a\u6307\u5b9a\u5141\u8bb8\u7684\u8de8\u57df\u8bf7\u6c42\u65b9\u6cd5\n\n- \u5fc5\u586b\u3001\u591a\u9009\n- \u586b\u5199\u5141\u8bb8Headers\uff1a\u6307\u5b9a\u5141\u8bb8\u7684\u8de8\u57df\u8bf7\u6c42\u7684\u54cd\u5e94\u5934\n- \u5141\u8bb8\u591a\u6761\u5339\u914d\u89c4\u5219\uff0c\u591a\u6761\u89c4\u5219\u9700\u6362\u884c\u586b\u5199\n- \u5982\u679c\u6709\u901a\u914d\u7b26*\uff0c\u5219\u5355\u884c\u53ea\u80fd\u662f\u901a\u914d\u7b26*\n\n\u586b\u5199\u66b4\u9732Headers\uff1a\u6307\u5b9a\u5141\u8bb8\u7528\u6237\u4ece\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8bbf\u95ee\u7684\u54cd\u5e94\u5934\uff08\u4f8b\u5982\uff0c\u4e00\u4e2a Javascript \u7684 XMLHttpRequest \u5bf9\u8c61)\u3002\n\n- \u5141\u8bb8\u591a\u6761\u5339\u914d\u89c4\u5219\uff0c\u591a\u6761\u89c4\u5219\u9700\u6362\u884c\u586b\u5199\n- \u4e0d\u5141\u8bb8\u4f7f\u7528\u661f\u53f7*\u901a\u914d\u7b26\u3002\n\n\u586b\u5199\u7f13\u5b58\u65f6\u95f4\uff1a\u6307\u5b9a\u6d4f\u89c8\u5668\u5bf9\u7279\u5b9a\u8d44\u6e90\u7684\u9884\u53d6\uff08OPTIONS\uff09\u8bf7\u6c42\u8fd4\u56de\u7ed3\u679c\u7684\u7f13\u5b58\u65f6\u95f4\n\n- \u5355\u4f4d\uff1a\u79d2\n\n#### **\u4fee\u6539\u89c4\u5219**\n\n\u5df2\u6dfb\u52a0\u7684\u89c4\u5219\uff0c\u4ee5\u5217\u8868\u5c55\u793a\uff1a\n\n![](https:\/\/tp2lravq.hk03.1112oss.com\/202308171713248fkf41231jitlqsbowtpqokpq9fp2t4q.png)\n\n\u70b9\u51fb\u89c4\u5219\u5217\u8868\u300c\u64cd\u4f5c\u300d\u5217\u7684\u300c\u7f16\u8f91\u300d\u56fe\u6807\uff0c\u53ef\u4ee5\u4fee\u6539\u5df2\u6709\u89c4\u5219\u7684\u53c2\u6570\uff1a\n\n- \u8de8\u57df\u89c4\u5219\u6240\u4ee5\u53c2\u6570\u90fd\u53ef\u4ee5\u4fee\u6539\n\n#### **\u5220\u9664\u89c4\u5219**\n\n\u5df2\u6dfb\u52a0\u7684\u89c4\u5219\u4e0d\u518d\u9700\u8981\u65f6\uff0c\u53ef\u4ee5\u5220\u9664\u3002\n\n\u76ee\u524d\u53ea\u652f\u6301\u5355\u6761\u548c\u6279\u91cf\u5220\u9664\u3002\n\n- \u5728\u89c4\u5219\u5217\u8868\u4e2d\uff0c\u70b9\u51fb\u4efb\u4e00\u884c\u300c\u64cd\u4f5c\u300d\u5217\u7684\u300c\u5220\u9664\u300d\u56fe\u6807\uff0c\u5373\u53ef\u5220\u9664\u6389\u6b64\u89c4\u5219\n\n- \u9009\u62e9\u591a\u4e2a\u89c4\u5219\uff0c\u70b9\u51fb\u300c\u8de8\u57df\u8bbe\u7f6e\u300d\u6846\u4e2d\u7684\u300c\u6279\u91cf\u5220\u9664\u300d\u6309\u94ae\uff0c\u53ef\u4ee5\u6279\u91cf\u5220\u9664\u6307\u5b9a\u89c4\u5219"}