【问题标题】:Testing server's response测试服务器的响应
【发布时间】:2014-04-14 10:22:40
【问题描述】:

我的 Angular 应用程序中有一个表单,用户需要在其中提供有效的 url。 因此,在提交表单时,我想通过向提供的 url 发出 get 请求并检查服务器是否发送 200 来测试该 URL 是否有效。

当点击提交按钮时,会运行以下代码:

$http.get(scope.target_url).success(function(){
                // some code 
            }).error(function(error){
                console.log(error);
            });

但是,我从未得到成功的答案: - 如果我提供一个类似“http://www.somesite.com”的网址,我会得到:

XMLHttpRequest cannot load 'http://www.somesite.com'. Received an invalid response. Origin 'mydomain' is therefore not allowed access.
  • 如果我提供类似“http://somesite.com”的网址,我会得到:

    XMLHttpRequest 无法加载 http://somesite.com/。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'mydomain' 不允许访问。

问题出在哪里?

【问题讨论】:

标签: javascript angularjs http get


【解决方案1】:

这是正常的安全约束。在此处阅读有关 CORS 的信息:

http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多