- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
<分区>
我在启用了 Windows 身份验证的后端使用 angular 4 和 ASP.NET web api 2。我有一个帖子和一个获取 api。 GET 工作正常。但是对于 POST 我收到了这个错误
Response for preflight has invalid HTTP status code 401
这意味着我收到了 OPTIONS 方法的未授权错误,我知道这不应该是这种情况,因为永远不会使用用户凭据调用 OPTIONS 方法。
在angular中我调用api如下
let requestOptions = new RequestOptions({
withCredentials: true,
headers: new Headers({
'content-type': 'application/json'
})
})
this.http.post("someapiendpoint", JSON.stringify(data), requestOptions).subscribe(data => {
debugger;
});
我已经在我的网络配置中设置了所有 CORS header ,如下所示
<add name="Access-Control-Expose-Headers " value="WWW-Authenticate"/>
<add name="Access-Control-Allow-Origin" value="http://localhost:4200" />
<add name="Access-Control-Allow-Headers" value="accept, authorization, Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
我的 web.config 身份验证 block 中也有以下内容
<authentication>
<anonymousAuthentication enabled="false" userName="" />
<basicAuthentication enabled="false" />
<clientCertificateMappingAuthentication enabled="false" />
<digestAuthentication enabled="false" />
<iisClientCertificateMappingAuthentication enabled="false">
</iisClientCertificateMappingAuthentication>
<windowsAuthentication enabled="true">
<providers>
<add value="Negotiate" />
<add value="NTLM" />
</providers>
</windowsAuthentication>
</authentication>
我试过删除
headers: new Headers({
'content-type': 'application/json'
})
以下是我的 web api Controller 代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
namespace Backend.Controllers
{
public class DemoController : ApiController
{
Entities db = new Entities();
public DemoController ()
{
}
[HttpPost]
[ActionName("postevent")]
public IHttpActionResult PostEvent(Demo data)
{
db.Demos.Add(data);
db.SaveChanges();
return Ok();
}
}
}
来 self 的 Angular 代码,但它没有帮助。我也尝试用“text/html”替换它,但这也不起作用。有人能告诉我我做错了什么吗?正如我所假设的那样,如果它适用于 GET,它应该可以正常工作。
我在 swagger.mydomain.com 上运行了 swagger (docker: swaggerapi/swagger-ui),并为在 a.mydomain.com 和 b.mydomain
在我的应用程序中,进行以下两步调用时,我在第二个 AJAX 调用中收到预检错误: $.ajax({ type:'POST', url:'https://podio.com/oauth/
我们在 Istio 中使用 Kubernetes 并配置了一个虚拟服务: http: - match: - uri: prefix: /api rewrite:
我有一个 Firebase Callable Cloud Function我在浏览器的 javascript 应用程序中调用它。 因为请求主机是 ...cloudfunctions.net 而不是我的
这个问题在这里已经有了答案: XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header (11 个答案) 关闭 3
我目前对如何“选择”或选择在请求之前执行 Angular 的(jquery)预检 OPTIONS 调用感到困惑。 我有一个正常的 RESTful api 调用 (api.domain.co) 我已在主
我用 C# 创建了一个 WebService。所有 GET 方法都可以正常工作。 现在我需要提供一些 POST 方法。通过 C# 调用它时,它可以正常工作。然后我尝试用 JavaScript 编写一个
我正在尝试向我的 REST API 发出 POST 请求。这是代码片段(使用 AngularJS): $http({ method: 'POST',
我正在使用 rack-cors 中间件从站点向我的 Rails 应用程序发出跨域请求(尽管我不认为这个问题特定于 rack-cors)。当我用 Firebug 检查控制台输出时,我注意到只有一个请求发
我正在使用 rack-cors 中间件从站点向我的 Rails 应用程序发出跨域请求(尽管我不认为这个问题特定于 rack-cors)。当我用 Firebug 检查控制台输出时,我注意到只有一个请求发
您好,我正在尝试在 Debian 8 Jessie 中设置 DC/OS,我使用 ssh key 建立了 ssh 连接,我能够在没有密码的情况下登录到所有主机和代理(他们正在运行 CentOS 7)。奇
我正在制作一个简单的网络应用程序,它与我无法控制的服务器进行通信。 起初我配置了一个自定义的 $resource GET 请求并且工作正常。现在我需要做一个 POST 请求来从同一台服务器请求一些信息
我正在构建一个带有 Spring Boot 后端的 Angular 2 应用程序。几天来,我一直在尝试解决 CORS 预检的问题。根据这个topic ,它应该像这样与 CORS 过滤器一起工作: @C
我需要将 CORS 过滤器添加到我的 Spring Boot Web 应用程序中。 我添加了如下文档中所述的 CORS 映射 http://docs.spring.io/spring/docs/cur
我正在尝试对我部署的用于检索 JSON 数据的 Azure 函数进行 POST。我收到 CORS 错误。 有权从来源“http://localhost:3000”在“{API URL}”获取数据' 已
我有一个 Angular 应用程序和 Node 后端,所有请求都正常工作,但是当我尝试使用 get 请求并且在其中重定向请求时,会发生“CORS 预检 channel 未成功”此错误。 .当我在 po
我正在尝试获取名为 X-Total-Pages 的自定义 header 当我做GET时 Ajax 调用。调用从客户端发送到 API。API 允许使用以下 header : Access-Control
我正在尝试在 OS X 10.11.3 上运行 Plone 统一安装程序(适用于 4.3.9)不 使用 --without-ssl 选项,并且我收到以下错误: Unable to find libss
我的架构中有三个应用程序。 它们在同一台服务器上,但具有不同的端口号。 A - Token Application (port 4444) - Asp.net WebApi B - API Appli
所以我有一个不寻常的问题,我不确定如何进行调试。我有一个 angular 4 应用程序,它在服务器端使用 cakephp。 在我的应用程序中,我可以访问许多不同的屏幕,除了一个并且它只是 Firefo
我是一名优秀的程序员,十分优秀!