POST 请求适用于 Postman,但不适用于 Angular 11

时间:2021-05-06 12:45:32

标签: javascript angular typescript http-post angular-httpclient

我有一个 ping Django 后端的 HTTP post 请求。当从 Postman 发出请求时,我能够得到有效的响应。但是从 Chrome 触发,使用语义相同的 json 负载,我收到 400 错误请求。

Image of the Services

Post man example

以下是我使用的 json 模型,以 angular 构建主体。

标题保持不变,授权也完全相同(使用基本身份验证)。我唯一能想到的问题是 CORS,但是,我正在代理它来解决这个问题。

export class RealResult {
  node: string;
  source: string;
  destination: string;
  protocol: string;
  source_port: string;
  destination_port: string;
  direction: string;
  acl_ID: string;
  zone: string;
  action: string;
  timestamp: string;
  flowID: string;

  constructor(data: RealResult) {
    this.node = data.node;
    this.source = data.source;
    this.destination = data.destination;
    this.protocol = data.protocol;
    this.source_port = data.source_port;
    this.destination_port = data.destination_port;
    this.direction = data.direction;
    this.acl_ID = data.acl_ID;
    this.zone = data.zone;
    this.action = data.action;
    this.timestamp = data.timestamp;
    this.flowID = data.flowID
  }
}

export class Success {
  results: Result[];

  constructor() {
    this.results = []
  }
}

0 个答案:

没有答案
相关问题