我试图在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 config上设置了标题
<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 app中设置了相同的标题。
我收到了这个回复:
状态代码:501未实现
答案 0 :(得分:0)
尝试使用headers.append()
let headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');