简体   繁体   English

为什么我在Cloud9中的http请求总是返回错误?

[英]Why does my http request in Cloud9 always return an error?

I am currently developing a Cloud9 plugin, where I need to make a GET request to a remote web server. 我目前正在开发Cloud9插件,我需要向远程Web服务器发出GET请求。 The following code is what I use to perform the request: 以下代码是我用来执行请求的代码:

var http = imports.http;
http.request(url, {}, function(err, data, res) {
    if(err) {
        alert(err);
    }
}

When I perform the same GET request in a web browser, valid JSON is returned. 当我在Web浏览器中执行相同的GET请求时,将返回有效的JSON。 However, using this code, I always receive an Error object, which tells me that the number of loaded bytes is 0. What is going wrong? 但是,使用此代码,我总是收到一个Error对象,它告诉我加载的字节数是0.出了什么问题?

The answer I received from the c9 community is the following: The reason is an unpermitted cross origin request (the URL points to a java servlet running on the same host inside a jetty server). 我从c9社区收到的答案如下:原因是未经许可的交叉源请求(URL指向在jetty服务器内的同一主机上运行的java servlet)。 The solution is therefore to include an Access-Control-Allow-Origin Header in the servlet's Response. 因此,解决方案是在servlet的响应中包含一个Access-Control-Allow-Origin标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM