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

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

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

<legend id='NsF7N'><style id='NsF7N'><dir id='NsF7N'><q id='NsF7N'></q></dir></style></legend>

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

    1. <tfoot id='NsF7N'></tfoot>
    2. 播放 2.0.1 并設(shè)置 Access-Control-Allow-Origin

      Play 2.0.1 and setting Access-Control-Allow-Origin(播放 2.0.1 并設(shè)置 Access-Control-Allow-Origin)

        <tbody id='PoddW'></tbody>
            <bdo id='PoddW'></bdo><ul id='PoddW'></ul>
            <legend id='PoddW'><style id='PoddW'><dir id='PoddW'><q id='PoddW'></q></dir></style></legend>

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

            • <tfoot id='PoddW'></tfoot>

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

                本文介紹了播放 2.0.1 并設(shè)置 Access-Control-Allow-Origin的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我有一個 Play 2.0.1 應(yīng)用程序,我想使用托管在其他域上的 Javascript 來調(diào)用它.我的 Javascript 調(diào)用失敗:

                I have a Play 2.0.1 application that I want to call using Javascript hosted on other domains. My Javascript call is failing with:

                Origin http://mydomain.com is not allowed by Access-Control-Allow-Origin.
                

                我找到了一些關(guān)于如何在 Play 1 中設(shè)置正確 HTTP 標(biāo)頭的示例,但沒有找到適用于 Play 2.0.1 的任何內(nèi)容.閱讀文檔 (http://www.playframework.org/documentation/2.0.2/JavaResponse) 后,我嘗試了以下操作以使事情正常進(jìn)行:

                I have found a number of examples of how to set the correct HTTP header in Play 1, but have not found anything for Play 2.0.1. After reading the documentation (http://www.playframework.org/documentation/2.0.2/JavaResponse) I've tried the following just to get things working:

                public static Result myJsonWebService() {
                  ...
                  response().setHeader("Access-Control-Allow-Origin", "*");
                  return ok(toJson(jsonObject));
                }
                

                但我的 JS Web 服務(wù)調(diào)用仍然失敗.

                but my JS web service call is still failing.

                我需要做什么才能讓它工作?

                What do I need to do to get this working?

                推薦答案

                對于 Scala 的人來說,這是我目前正在使用的實現(xiàn):

                Just for Scala guys, this is the implementation I'm currently using:

                import play.api.mvc._
                import scala.concurrent._
                import play.api.http.HeaderNames._
                
                /**
                 * Action decorator that provide CORS support
                 *
                 * @author Giovanni Costagliola, Nick McCready
                 */
                case class WithCors(httpVerbs: String*)(action: EssentialAction) extends EssentialAction with Results {
                    def apply(request: RequestHeader) = {
                        implicit val executionContext: ExecutionContext = play.api.libs.concurrent.Execution.defaultContext
                        val origin = request.headers.get(ORIGIN).getOrElse("*")
                        if (request.method == "OPTIONS") { // preflight
                            val corsAction = Action {
                                request =>
                                    Ok("").withHeaders(
                                        ACCESS_CONTROL_ALLOW_ORIGIN -> origin,
                                        ACCESS_CONTROL_ALLOW_METHODS -> (httpVerbs.toSet + "OPTIONS").mkString(", "),
                                        ACCESS_CONTROL_MAX_AGE -> "3600",
                                        ACCESS_CONTROL_ALLOW_HEADERS ->  s"$ORIGIN, X-Requested-With, $CONTENT_TYPE, $ACCEPT, $AUTHORIZATION, X-Auth-Token",
                                        ACCESS_CONTROL_ALLOW_CREDENTIALS -> "true")
                            }
                            corsAction(request)
                        } else { // actual request
                            action(request).map(res => res.withHeaders(
                                ACCESS_CONTROL_ALLOW_ORIGIN -> origin,
                                ACCESS_CONTROL_ALLOW_CREDENTIALS -> "true"
                            ))
                        }
                    }
                }
                

                要使用它,只需按以下方式裝飾您的操作:

                To use it just decorate your action in the following way:

                def myAction = WithCors("GET", "POST") {
                  Action { request =>
                    ???
                  }
                }
                

                這篇關(guān)于播放 2.0.1 并設(shè)置 Access-Control-Allow-Origin的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調(diào)用完成)
                JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                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)容)

                      <tbody id='QzsPi'></tbody>
                    <legend id='QzsPi'><style id='QzsPi'><dir id='QzsPi'><q id='QzsPi'></q></dir></style></legend>
                    <tfoot id='QzsPi'></tfoot>

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

                          主站蜘蛛池模板: 欧美区日韩区 | 久久av网站 | 国产精品美女久久久免费 | 成年人在线| 激情五月综合 | 一级片网址| 免费永久av| 精品久久久久久久久久久 | 国产精品亚洲综合 | 国产一级视屏 | 天天干视频在线 | 97国产在线观看 | 久久久久久国产精品免费免费狐狸 | xxxxx免费视频| 亚洲精品小视频在线观看 | 亚洲精品区 | 久久国产精品-国产精品 | 国产日韩91 | 国产成人精品免费 | 黄色香蕉视频在线观看 | 久久国产精品视频 | 国产不卡视频在线 | 亚洲精品电影 | 欧美视频在线播放 | 国产毛片毛片 | 久久一区二区精品 | 精品国产一区二区三区免费 | 一区二区三区精品视频 | 国产精品永久免费观看 | 一区二区三区四区在线免费观看 | 国产aⅴ爽av久久久久久久 | 日韩精品极品视频在线观看免费 | 黄色av观看| 欧美精品一区二区三区一线天视频 | 91社区在线观看播放 | 日本三级做a全过程在线观看 | 亚洲综合在线视频 | 久久国内精品 | 96国产精品久久久久aⅴ四区 | 国产精品久久久久久久久久 | 欧美最猛性xxxxx亚洲精品 |