Immer Methode LÖSCHEN ist nicht erlaubt, Access-Control-Allow-Methods in preflight Antwort

Ich bin mit jersey als meine restful-api-Implementierung. Im front-end, ich bin mit angularjs $http-service, um http-Anfrage. Wenn ich einen delete-Methode bekam ich immer folgende Fehlermeldung.

"Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response."  

Las ich einige Artikel und Sie sagen, ich brauche, um zu erlauben, löschen Sie auf "Access-Control-Allow-Methods". Ich habe setup die response filter wie unten, aber es hat noch solche problem. Was sollte ich sonst tun?

@Provider
public class CORSResponseFilter implements ContainerResponseFilter {

    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
        MultivaluedMap<String, Object> headers = responseContext.getHeaders();

        headers.add("Access-Control-Allow-Origin", "*");
        headers.add("Access-Control-Allow-Methods", "*");
    }
}

unten ist mein Winkel-code, um eine Anfrage zu:

$http({
            method: 'DELETE',
            url: remoteUrl,
            headers : {'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
                'ACCESS_TOKEN' : $cookieStore.get("access_token")
            },
            data : $httpParamSerializer({
                'id':id
            })
        }).success(function(data,status,headers,config) {
            $scope.refreshDepartments();
            console.log(data);
            alert("success");
        }).error(function(data,status,headers,config){
            console.log(data);
            alert("error");
        });
  • Haben Sie registriert die Anbieter in Ihrem web.xml oder application-Klasse?
  • Ich bin mit spring-boot und es funktioniert für andere Methode wie GET, POST. Nur nicht auf LÖSCHEN
InformationsquelleAutor Zhao Yi | 2016-04-02
Schreibe einen Kommentar