jjzjj

javascript - 无法加载资源 : the server responded with a status of 421 (Bad Request)

coder 2023-09-26 原文

我正在使用 Apple 的新 CloudKit JS 引用和示例代码来构建一个简单的 CRUD 应用程序。在我什至可以到达 CRUD 之前,我被 Apple 身份验证阻止了。

index.html
<html>
<body>

<div id="apple-sign-in-button">Sign in
       <span id="username"></span>
</div>

<script>
    /*
     * Initialize the global objects we will need.
     */
    if(typeof CKCatalog === 'undefined') {
        CKCatalog = {};
    }

    if(typeof CKCatalog.tabs === 'undefined') {
        CKCatalog.tabs = {
            'readme': [{}],
            'not-found': [{}]
        };
    }
</script>

<script src="js/init.js"></script>
<script src="js/cloudkit-code-samples/authentication.js"></script>
<script>
    window.addEventListener('cloudkitloaded',CKCatalog.init);
</script>
<script async src="https://cdn.apple-cloudkit.com/ck/1/cloudkit.js">    </script>

</body>

包括 div id="apple-sign-in-button"和 span id="username"消除了所有错误,除了:

无法加载资源:服务器响应状态为 421(错误请求)。

在其他任何地方提及此错误通常都与 SMTP 或 FTP 相关。知道发生了什么事吗?

最佳答案

CloudKit.js 库是 CloudKit Web 服务的包装器,its documentation指出当调用需要身份验证但用户未登录的请求时会发生 HTTP 421。

这是预期的,因为您的应用可能需要确定用户是否已登录,如果没有,则显示相应的登录按钮。 CloudKit Catalog example's section on Authentication展示了如何通过调用 container.setUpAuth() 进行设置,这将检查用户并在未检测到用户时呈现“登录”按钮。这可能发生在您的 init.js 代码中,但在没有看到它的情况下我无法确定。

我看到您的页面上有 apple-sign-in-button div。如果您正在调用 setUpAuth 方法,那么您应该会看到在其中呈现的登录按钮。

一旦用户点击该按钮并登录,您就可以重新发出收到 421 的原始请求,并且应该会收到有效的 200。

请不要忘记,如果您想保留用户的 CloudKit session ,您可以在初始化容器时使用 auth: { persist: true }(有关更多信息,请参阅 CloudKit.js 文档)。

您还需要确保已在 CloudKit 仪表板中为您的容器创建了一个 API token 。这是您在初始化容器时使用的 token 。查看有关 CloudKit JS 和 Web 服务的 WWDC 2015 视频,观看相关演示。

希望对您有所帮助!

更新:

测试您的网络应用程序时,请确保您已配置 API token (使用 CloudKit 仪表板)以允许您正在测试的域(例如 localhost)。这最初是 Sam 的问题,但 localhost 现在是开发环境中 API token 的受支持域。

关于javascript - 无法加载资源 : the server responded with a status of 421 (Bad Request),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30878380/

有关javascript - 无法加载资源 : the server responded with a status of 421 (Bad Request)的更多相关文章

  1. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  2. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  3. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  4. ruby - 如何在续集中重新加载表模式? - 2

    鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende

  5. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  6. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  7. ruby - RuntimeError(自动加载常量 Apps 多线程时检测到循环依赖 - 2

    我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("

  8. ruby - 无法覆盖 irb 中的 to_s - 2

    我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)

  9. ruby - 无法在 60 秒内获得稳定的 Firefox 连接 (127.0.0.1 :7055) - 2

    我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类

  10. ruby - 安装 Ruby 时遇到问题(无法下载资源 "readline--patch") - 2

    当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub

随机推荐