1
에 전달하기 전에 응답 헤더를 제거하는 것은 상황 : 나는 항목을 작성하고 새 항목 위치에와 "만든 201"를 반환 할 것으로 예상하는 서버에 POST 요청을 AngularJS와 내 컨트롤러 여기
Location Header에서 두 번째 요청을하고 전체 항목 데이터를 가져옵니다. 내 파이어 폭스 콘솔에서// console.log(response.headers)
[content-type,] { content-type="application/json; charset=utf-8"}
: 나는 내 컨트롤러에서 위치 헤더를 얻을 때
Status Code: 201 Created
Connection: keep-alive
Content-Length: 17
Content-Type: application/json
Date: Thu, 22 Sep 2016 08:52:20 GMT
Location: /tasks/4
access-control-allow-headers: Content-type, Cache-Control, Keep-Alive, Location
access-control-allow-methods: GET, POST, PUT, DEL, OPTIONS
access-control-allow-origin: *
access-control-expose-headers: Content-type, Cache-Control, Keep-Alive, Location
그럼, 내가 얻을 :
이들은 서버가 보낸 응답 헤더입니다 다음을 시도하면 오류가 발생합니다.
response.headers['Location']
참고 : 각도 1.5.8을 사용하고 있습니다.
app.controller('NewTaskCtrl', function($scope, $http){
$scope.taskName = null
$scope.createTask = function(){
var data=JSON.stringify({ Name: $scope.taskName})
$http.post('http://192.168.1.129:9999/api/tasks',data)
.then(
function(response){
// error Here => console.log('Received Headers', response.headers)
console.log('Received Headers', response.headers())
// Error here => $http.get('http://192.168.1.129:9999'+response.headers['Location'])
$http.get('http://192.168.1.129:9999'+response.headers('Location'))
.then (
function(response){
$scope.Tasks.push(response)
},
function(reason){
alert("Unexpected Error Ocurred:\n"+JSON.stringify(reason))
}
)
},
function(reason){
alert("Unexpected Error Ocurred:\n"+JSON.stringify(reason))
}
)
}
})
내가 헤더를 잃고 왜 어떤 생각을하고 어떻게 그들을 얻을 수 있습니다 여기에 $ HTTPS
에 대한 mmended "약속"변종 내 컨트롤러 코드의 발췌 한 것입니다?
EDIT. 나는 헤더 함수가 아닌 객체이기 때문에
나는 지금 바보 같다고 생각합니다. 어쨌든, 많은 시간과 당신의 답변에 감사드립니다. – mtsdev