久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='pFMtw'></bdo><ul id='pFMtw'></ul>
    <legend id='pFMtw'><style id='pFMtw'><dir id='pFMtw'><q id='pFMtw'></q></dir></style></legend>

      <tfoot id='pFMtw'></tfoot>

      <i id='pFMtw'><tr id='pFMtw'><dt id='pFMtw'><q id='pFMtw'><span id='pFMtw'><b id='pFMtw'><form id='pFMtw'><ins id='pFMtw'></ins><ul id='pFMtw'></ul><sub id='pFMtw'></sub></form><legend id='pFMtw'></legend><bdo id='pFMtw'><pre id='pFMtw'><center id='pFMtw'></center></pre></bdo></b><th id='pFMtw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='pFMtw'><tfoot id='pFMtw'></tfoot><dl id='pFMtw'><fieldset id='pFMtw'></fieldset></dl></div>
    1. <small id='pFMtw'></small><noframes id='pFMtw'>

      使用 Polymer Iron-ajax 和 Node.js 發(fā)出 CORS 請求

      Make CORS Request with Polymer iron-ajax and Node.js(使用 Polymer Iron-ajax 和 Node.js 發(fā)出 CORS 請求)
          <i id='9ltdw'><tr id='9ltdw'><dt id='9ltdw'><q id='9ltdw'><span id='9ltdw'><b id='9ltdw'><form id='9ltdw'><ins id='9ltdw'></ins><ul id='9ltdw'></ul><sub id='9ltdw'></sub></form><legend id='9ltdw'></legend><bdo id='9ltdw'><pre id='9ltdw'><center id='9ltdw'></center></pre></bdo></b><th id='9ltdw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9ltdw'><tfoot id='9ltdw'></tfoot><dl id='9ltdw'><fieldset id='9ltdw'></fieldset></dl></div>
          • <bdo id='9ltdw'></bdo><ul id='9ltdw'></ul>
            <legend id='9ltdw'><style id='9ltdw'><dir id='9ltdw'><q id='9ltdw'></q></dir></style></legend>

              <tbody id='9ltdw'></tbody>

            1. <tfoot id='9ltdw'></tfoot>

            2. <small id='9ltdw'></small><noframes id='9ltdw'>

              1. 本文介紹了使用 Polymer Iron-ajax 和 Node.js 發(fā)出 CORS 請求的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試使用 Polymer 和 Node 檢索數(shù)據(jù),但正在努力獲得有效的響應.我收到一個飛行前響應錯誤,提示 access-control-allow-origin 是不允許的.

                I am trying to retrieve data using Polymer and Node, but am struggling to get a valid response back. I get a pre-flight response error that says the access-control-allow-origin is not allowed.

                我在 localhost:4001 上運行 Polymer,在 localhost:8080 上運行 Node.

                I am running Polymer on localhost:4001 and Node on localhost:8080.

                如何配置節(jié)點或客戶端以加載響應?

                How can I configure either Node or the Client to load a response?

                客戶

                <iron-ajax id="ajaxUser"
                  url="http://localhost:8080/node/api/mssql/login"
                  method="post"
                  handle-as="json"
                  Content-Type="application/json"
                  headers='{"Access-Control-Allow-Origin": "*"}'
                  params="[[params]]"
                  on-response="saveUserCredentials"
                  last-response="{{user}}"></iron-ajax>
                

                節(jié)點

                const corsOptions = {
                  allowedHeaders: ['Content-Type', 'Access-Control-Allow-Origin']
                }
                
                app.options('*', cors(corsOptions))
                

                ...

                app.use((req, res, next) => { // Enable Cross-Origin Resource Sharing (CORS)
                  res.header("Access-Control-Allow-Origin", "*")
                  res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT")
                  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, x-api-key")
                  next()
                })
                

                錯誤

                加載失敗
                http://localhost:8080/login?username=user&password=password:
                請求的資源上不存在Access-Control-Allow-Origin"標頭.
                因此,Origin 'http://localhost:4001' 是不允許訪問的.響應的 HTTP 狀態(tài)代碼為 400.

                Failed to load
                http://localhost:8080/login?username=user&password=password:
                No 'Access-Control-Allow-Origin' header is present on the requested resource.
                Origin 'http://localhost:4001' is therefore not allowed access. The response had HTTP status code 400.

                推薦答案

                問題代碼段中的Node配置沒有處理OPTIONS請求.

                The Node configuration in the code snippet in the question doesn’t handle OPTIONS requests.

                為了確保正確處理 CORS 預檢,考慮安裝 npm cors 包:

                To ensure CORS preflights get handled correctly, consider installing the npm cors package:

                npm install cors
                

                然后做這樣的事情:

                var express = require('express')
                  , cors = require('cors')
                  , app = express();
                app.options('*', cors()); // preflight OPTIONS; put before other routes
                

                這將處理預檢響應和其他 CORS 方面,而無需您在應用程序代碼中從頭開始手動編寫自己的處理.

                That’ll handle the preflight response and other CORS aspects without you needing to manually write your own handling from scratch in your application code.

                https://www.npmjs.com/package/cors#configuration-option 提供了所有選項的更多詳細信息.

                https://www.npmjs.com/package/cors#configuration-option has more details on all the options.

                這篇關于使用 Polymer Iron-ajax 和 Node.js 發(fā)出 CORS 請求的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                XmlHttpRequest onprogress interval(XmlHttpRequest onprogress 間隔)
                How can I modify the XMLHttpRequest responsetext received by another function?(如何修改另一個函數(shù)接收到的 XMLHttpRequest 響應文本?)
                What is the difference between XMLHttpRequest, jQuery.ajax, jQuery.post, jQuery.get(XMLHttpRequest、jQuery.ajax、jQuery.post、jQuery.get 有什么區(qū)別)

                    <bdo id='vC9kO'></bdo><ul id='vC9kO'></ul>

                    <small id='vC9kO'></small><noframes id='vC9kO'>

                      <tbody id='vC9kO'></tbody>
                    1. <legend id='vC9kO'><style id='vC9kO'><dir id='vC9kO'><q id='vC9kO'></q></dir></style></legend>

                        <i id='vC9kO'><tr id='vC9kO'><dt id='vC9kO'><q id='vC9kO'><span id='vC9kO'><b id='vC9kO'><form id='vC9kO'><ins id='vC9kO'></ins><ul id='vC9kO'></ul><sub id='vC9kO'></sub></form><legend id='vC9kO'></legend><bdo id='vC9kO'><pre id='vC9kO'><center id='vC9kO'></center></pre></bdo></b><th id='vC9kO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vC9kO'><tfoot id='vC9kO'></tfoot><dl id='vC9kO'><fieldset id='vC9kO'></fieldset></dl></div>
                        • <tfoot id='vC9kO'></tfoot>
                          主站蜘蛛池模板: 日本一区二区高清视频 | 在线视频一区二区 | 一级毛片视频 | 一区二区三区久久 | 97精品一区二区 | 精品久久久久久久久久久久 | 欧美mv日韩mv国产网站91进入 | 欧美精品第一页 | 久久久久国产一区二区三区四区 | 欧美日韩在线观看视频网站 | 久久综合九九 | 97伦理最新伦理 | 亚洲网站在线 | 青青草中文字幕 | 99热.com| 国产精品有限公司 | 国产成人麻豆免费观看 | 91精品国产美女在线观看 | 亚洲欧美日韩在线一区二区 | 亚洲精品在线免费观看视频 | 男女下面一进一出网站 | 九九热在线视频 | 日日干夜夜操 | 欧美黑人国产人伦爽爽爽 | 黄色成人在线网站 | 免费午夜视频 | 国产国拍亚洲精品av | 成人av一区二区三区 | 91精品国产一二三 | 精品亚洲一区二区三区四区五区高 | 99视频在线 | 81精品国产乱码久久久久久 | 久久婷婷国产麻豆91 | 久久久精品综合 | 国产免费视频 | 成人免费视频久久 | 久久久影院 | www.99re| 久久久久国产精品一区二区 | 中文字幕一区二区三区在线观看 | 欧美黑人一级爽快片淫片高清 |