【问题标题】:How do I config the API in ASP.NET Core for access the http request?如何在 ASP.NET Core 中配置 API 以访问 http 请求?
【发布时间】:2019-12-09 15:16:17
【问题描述】:

我想将数据发送到后端,以便使用带有 API URL 的 http post 方法创建有关客户的详细信息。但它拒绝连接后端。因为它需要一些权限才能访问 post 方法。请给出一些指导方针并解决此错误。

我已经在 app.setting 中对后端的 Allow-permission-* 进行了一些更改。但什么也没发生。

    //This is my ts code

    this.http.post('http://localhost:2401/api/CustomerAPI', 
    jstring).map(res => res.json()).subscribe(data => {
    console.log(data)
  }, (err) => {
    console.log(err)
  });
}

从源“http://localhost:8100”访问“http://localhost:2401/api/CustomerAPI”处的 XMLHttpRequest 已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。

然后它也显示Failed to load resource: net::ERR_CONNECTION_REFUSED

【问题讨论】:

  • 能否提供 CustomerAPI 邮政编码
  • var jstring = JSON.stringify({ CodeId: this.Code, customerNameId: this.CustomerName, ProjectnameId: this.Projectname, SortcodeId: this.Sortcode, contactId: this.contact, AddressId: this.地址,Address2Id:this.Address2,CountryId:this.Country,PostalcodeId:this.Postalcode,PhoneId:this.Phone,FaxId:this.Fax,CheckeboxId:this.Checkebox,DescriptionId:this.Description
  • 我想在“appsettings.json”的后端做一些访问权限

标签: angular sqlite asp.net-core asp.net-web-api ionic3


【解决方案1】:

您遇到了 CORS 问题,请阅读此CORS in .NET 另外,一个解决方案是.NET CORS solution

【讨论】:

  • 我已经很红了,我是 .net 的新手,所以我无法理解。他们在那里解释了什么???你能通过其他方式帮助我吗?
  • 您需要配置您的服务器以允许标头、方法、来源,以便您的客户端应用程序(离子应用程序)可以向您的服务器发送请求并获得响应。单击此链接并完全按照他们列出的内容进行操作 [解决方案] (stackoverflow.com/a/45844400/6800815)
  • 哇,非常感谢您的参考……那里已经清楚地解释了。
  • 我该怎么做?因为我是新来的!
  • 在 [这里] (meta.stackexchange.com/questions/173399/…) 了解更多信息
猜你喜欢
  • 2019-01-08
  • 2018-04-01
  • 2022-01-26
  • 1970-01-01
  • 2015-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多