2
我有一個嚴重的金字塔框架問題。 我添加此功能金字塔金字塔CORS doest不能提供PUT和DELETE
add_cors_headers_response_callback(event):
def cors_headers(request, response):
response.headers.update({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST,GET,DELETE,PUT,OPTIONS',
# 'Access-Control-Allow-Methods': 'DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept, Authorization',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Max-Age': '1728000',
})
event.request.add_response_callback(cors_headers)
from pyramid.events import NewRequest
config.add_subscriber(add_cors_headers_response_callback, NewRequest)
我可以使用GET,POST方法也求到我的服務器。 問題是當我使用PUT和DELETE方法服務器發送HTTP狀態404,但是當我捲曲的路線我得到答案(或使用POSTMAN)。
我在Node.JS中使用了相同的Angular http查詢,它接受我的請求。 我不知道爲什麼金字塔拒絕服務視圖
updatePatternModel(newPattern,url) {
let fullurl = this.baseUrl + url;
let data = {
"rule":newPattern
};
return this.http.put(fullurl,JSON.stringify(data))
.map(response => response.json())
.catch(err => this.handleErrorObservable(err));
}
金字塔
@view_config(request_method='PUT', route_name='gm')
def gm(self):
return dict()
EDITED
我做出了榜樣
from pyramid.view import view_config
@view_config(route_name='gm', renderer='json',request_method="GET")
def get(request):
return dict(hello="GET")
@view_config(route_name='gm', renderer='json',request_method="POST")
def post(request):
return dict(hello="POST")
@view_config(route_name='gm', renderer='json',request_method="PUT")
def put(request):
return dict(hello="PUT")
@view_config(route_name='gm', renderer='json',request_method="DELETE")
def delete(request):
return dict(hello="DELETE")
GET/POST的作品,但PUT ,刪除不!
import { Injectable } from '@angular/core';
import {Http} from "@angular/http";
import "rxjs/add/operator/map"
@Injectable()
export class AppService {
baseUrl : string = "http://10.0.0.34:8880"
constructor(public http:Http) { }
getData(url) {
console.log('hi');
let full_url= this.baseUrl + url;
return this.http.get(full_url)
.map(response => response.json());
}
postData(url) {
console.log('hello');
let full_url= this.baseUrl + url;
return this.http.post(full_url,null)
.map(response => response.json());
}
putData(url) {
console.log('hello');
let full_url= this.baseUrl + url;
return this.http.put(full_url,null)
.map(response => response.json());
}
deleteData(url) {
console.log('hello');
let full_url= this.baseUrl + url;
return this.http.delete(full_url)
.map(response => response.json());
}
}
似乎你的問題不涉及到CORS,因爲在這種情況下,應用程序將不會返回404。瀏覽器只會阻止請求。如果我是你,我會找別的地方。 –
編輯,PLZ審查的問題 –