簡體   English   中英

AngularJS $ http設置頭

[英]AngularJS $http setting headers

我正在嘗試在AngularJS中設置http,但看來我做錯了。

app.controller("mainCtrl", function ($scope, $http) {
    $http({
        method: 'GET',
        url: '***',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    }).success(function (data, status, headers, config) {
        console.log("data", data);
        console.log("status", status);
        console.log("headers", headers);
        console.log("config", config);
    }).error(function (data, status, headers, config) {
        console.log("data", data);
        console.log("status", status);
        console.log("headers", headers);
        console.log("config", config);
    })
})

我的主要興趣是設置accept: json ,但是如果我在Google Chrome瀏覽器的開發工具中檢查請求標頭,它始終只會顯示Accept:\\*/\\*

編輯:在服務器上設置了CORS,但我仍然收到此錯誤,但無響應。

XMLHttpRequest cannot load http://inpro.smid.co.cz:8080/InproRestApi/webresources/entities.regions. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

如果您檢查服務器是否已配置Access-Control-Allow-Origin標頭,則可能是CORS問題。

在控制器類中簡化添加,如下所示

@CrossOrigin(origins =“ *”)公共類控制器{

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM