【问题标题】:JSON file not found upon uploading compiled Dart application上传已编译的 Dart 应用程序时未找到 JSON 文件
【发布时间】:2014-09-16 05:40:37
【问题描述】:

我最近对Dart 产生了兴趣,并关注了他们的教程海盗徽章。完成后,我构建它并上传到我的网络服务器。在应用程序启动时,它会调用一个 .json 文件:

static Future readyThePirates() {
    var path = 'piratenames.json';
    return HttpRequest.getString(path).then(_parsePirateNamesFromJSON);
}

void main() {
    //... other code
    PirateName.readyThePirates()
        .then((_) {
            inputField.disabled = false;
            genButton.disabled = false;
            setBadgeName(getBadgeNameFromStorage());
         })
        .catchError((arrr){
            print('Error initializing pirate names: $arrr');
            badgeNameElement.text = 'Arrr! No names.';
         });
    }
    //... more code
}

这是我的 FTP 屏幕:

显然该文件在那里,但是当我在浏览器中加载它时出现错误。在 Chrome 中检查我得到了这个:

当我在 Dartium(从 Dart 编辑器)中运行它时,它工作得很好,不知道为什么它在实时页面上出现问题。

有人知道会发生什么吗?

【问题讨论】:

  • 您服务器上 JSON 文件的实际 URL 是什么?
  • 会不会是您的文件不在推荐的位置,而pub 因此没有将必要的文件复制到构建目录中?看起来您的文件位于项目的顶层,而不是位于 binlib 的目录中。
  • 好吧,根据他在屏幕截图中显示的内容,我们可以查看web/,这应该可以。 @Anders 你能提供更多背景信息吗?
  • 我在 Dart IDE 中运行了编译器,您在 FTP 上看到的正是它在发布文件夹中提供的内容,pub 我相信。
  • 所有这些文件都在服务器上的/pirate/ 目录中。它是应用程序的根文件夹。

标签: json ftp dart http-status-code-404


【解决方案1】:

你在使用 IIS 吗?

我最近发现了IIS would serve up 404s for any file extension it didn't know the mime type for;所以当我在磁盘上看到它们时,我的 .sqlite 文件会显示 404!

你可以在 IIS 管理界面中修复它,基本上只是编辑你的 web.config,插入如下内容:

<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension="json" mimeType="text/plain" />
    </staticContent>
  </system.webServer>
</configuration> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    • 2015-09-15
    • 1970-01-01
    • 2019-01-17
    相关资源
    最近更新 更多