【问题标题】:Angular 4, http post is giving giving error : XMLHttpRequest cannot loadAngular 4,http post给出错误:XMLHttpRequest无法加载
【发布时间】:2017-07-31 19:54:14
【问题描述】:

我正在开发一个关于 Angular 的应用程序,我是新手。

这是我的要求,我正在尝试使用 http post 获取数据。但它给出了以下错误。 XMLHttpRequest 无法加载 http://162.12.0.117:8081/Server/config/getAllConfigurationValues。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。 Origin 'http://localhost:4200' 因此不允许访问。

下面是我的代码。

    let headers = new Headers({ 'Content-Type': 'application/json'});

    let options = new RequestOptions({ headers: headers });
    this.http.post(
    "http://162.12.0.117:8081/Server/config/getAllConfigurationValues", 
    {
        "userName": "username",
        "password": "password"
    },
    options
    ).subscribe(
        (result) => function(){
            console.log(result);
        }
    );

【问题讨论】:

  • 你可以找到这个问题的答案,如果你试着搜索一个。
  • 跨源请求被大多数浏览器阻止。如果你使用 Chrome,看看这个问题:stackoverflow.com/questions/3102819/…

标签: angular


【解决方案1】:

服务器端应该允许跨源请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 2011-11-03
    • 2017-05-28
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多