【问题标题】:Apache CORS OPTIONS request status 501 errorApache CORS OPTIONS 请求状态 501 错误
【发布时间】:2018-02-11 12:29:49
【问题描述】:

Angular 2 http post 未设置内容类型

我试图在 http.post 上设置标题但没有运气。

import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions, Response } from '@angular/http';

import { User } from '../_models/index';

@Injectable()
export class UserService {
constructor(private http: Http) { }

create(username: string, firstname: string, lastname: string, email: string, password: string) {
    let headers = new Headers({
        'Accept' : 'application/json',
        'Content-Type': 'application/json'
    });
    let options = new RequestOptions({ headers: headers, method: 'post' });

    return this.http.post(
        'http://127.0.0.1:8080/api/users/register',
        JSON.stringify({username, firstname, lastname, email, password}),
        options
        // this.jwt()
    ).map(
        (response: Response) => response.json()
    );
}

我已经在我的 apache 配置中设置了标题

    <Directory /var/www/stockwatch_api>
            Header set Access-Control-Allow-Origin "*"
            Header set Access-Control-Allow-Headers "Content-Type"
            Header set Access-Control-Allow-Methods "POST, PUT, DELETE, GET, HEAD"

我还在我的 cakephp api 应用程序中设置了相同的标题。

我收到了这样的回复:

状态码:501 未实现

【问题讨论】:

标签: apache angular cakephp cors preflight


【解决方案1】:

尝试使用headers.append()

let headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');

【讨论】:

  • 您是否遇到任何错误?你在 teamviewer 中有空吗??
猜你喜欢
  • 2020-04-09
  • 2022-01-21
  • 2015-06-11
  • 2012-04-26
  • 2015-03-01
  • 2018-11-19
  • 1970-01-01
  • 2018-02-25
  • 2012-11-28
相关资源
最近更新 更多