【问题标题】:Connect app engine with ibm cloudant using XMLHttpRequest使用 XMLHttpRequest 将应用程序引擎与 ibm cloudant 连接起来
【发布时间】:2020-10-12 08:18:55
【问题描述】:

我在 Node.js 中使用标准应用引擎配置。我在使用 xmlhttprequest 从应用引擎访问 ibm cloudant 时遇到问题。

我用于应用引擎请求的代码如下:

var getAllDocuments = function(database, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET","<link>" + database + "/_all_docs?include_docs=true", false);
    xhr.setRequestHeader("Authorization", myauthenticateUser(userName, passWord));
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.onreadystatechange = function (){
        if (xhr.readyState == 4 && xhr.status == 200) {
         var data = JSON.parse(xhr.responseText);
         callback(data, xhr.status);
        }
        else{
            callback(null, xhr.status);
        }
    }
    xhr.send();
} 

执行上述代码时会发生以下错误-: Error: EROFS: read-only file system, open '.node-xmlhttprequest-sync-11'。

仅供参考:我没有在我的应用引擎中保存任何临时文件。

有什么要添加到我创建的 yaml 文件中的,还是其他的?

【问题讨论】:

    标签: node.js google-app-engine xmlhttprequest cloudant


    【解决方案1】:

    错误似乎不言自明:

    错误:EROFS:只读文件系统,打开.node-xmlhttprequest-sync-11

    这些文件是由于使用了同步请求而生成的。请查看此similar question,他们在其中启动“nodemon”,它不断创建文件.node-xmlhttprequest-sync-1516(最后是随机数)。

    另外,根据this我发现:

    从 Gecko 30.0(Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27)、Blink 39.0 和 Edge 13 开始,由于对用户体验的负面影响,主线程上的同步请求已被弃用。

    同步 XHR 现在处于弃用状态。

    因此,您可能会考虑重组代码以改用异步。

    我想搜索更多,我找到了this entry in github issues

    一般来说,如果您正在获取这些文件,则意味着您正在使用同步 http 请求,这是不可以的。由于这种影响和其他原因,您不应该这样做。请检查您的代码是否有同步请求并将其删除。

    如果您看到使用同步请求的 Truffle 代码,请告诉我们。

    我认为this responds to your question

    仅供参考,此文件不是松露生成的。它是在节点中使用同步 http 请求的结果。

    解决方案:更改为异步请求。为此,您必须更改此行

    xhr.open("GET","<link>" + database + "/_all_docs?include_docs=true", false);
    

    为此:

    xhr.open("GET","<link>" + database + "/_all_docs?include_docs=true", true);
    

    将标志 false 更改为 true。更多详情请查看this

    【讨论】:

      猜你喜欢
      • 2011-09-18
      • 1970-01-01
      • 2018-01-03
      • 2015-12-11
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多