久久久久久久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ù),但正在努力獲得有效的響應(yīng).我收到一個飛行前響應(yīng)錯誤,提示 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é)點或客戶端以加載響應(yīng)?

                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' 是不允許訪問的.響應(yīng)的 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 預(yù)檢,考慮安裝 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
                

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

                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.

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

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

                相關(guā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 部分內(nèi)容)
                XmlHttpRequest onprogress interval(XmlHttpRequest onprogress 間隔)
                How can I modify the XMLHttpRequest responsetext received by another function?(如何修改另一個函數(shù)接收到的 XMLHttpRequest 響應(yīng)文本?)
                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>
                          主站蜘蛛池模板: 欧美久久电影 | 精品日本久久久久久久久久 | 精品一区二区三区四区 | 欧美日韩在线精品 | 中文字幕 国产 | 亚洲一区二区三区四区五区中文 | 精品视频在线免费观看 | 欧美一级精品片在线看 | 精品久久久网站 | 国产日韩av一区二区 | 久草免费在线视频 | 日本特黄a级高清免费大片 成年人黄色小视频 | 男女视频在线观看免费 | 久久i | 91色网站 | 精品国产不卡一区二区三区 | 亚洲欧美激情四射 | 美女在线视频一区二区三区 | 四虎在线视频 | 中文字幕第一页在线 | 国产精品一区二区无线 | 国产中文字幕在线观看 | 在线视频一区二区三区 | 成人在线国产 | 九九热精品在线视频 | 黄色大片免费观看 | 国产91丝袜在线播放 | 亚洲一二三区在线观看 | 日韩成人影院 | 国产精品久久久久久福利一牛影视 | 欧美一级片在线观看 | 日韩在线观看视频一区 | av在线视 | 久久久精品综合 | 青娱乐国产 | 日韩成人一区 | 日韩中文字幕一区二区三区 | 国产精品1区2区3区 一区中文字幕 | 日韩综合网 | 国产欧美一区二区三区日本久久久 | av电影一区二区 |