2013-07-24 2 views
2

저는 JSON 데이터를 게시하기 위해 노력하고 있습니다.하지만 어떤 이유로 그것이 작동하지 않습니다. 나는 크롬 관리자의 요청을 검사 할 때

angular.module('pocket.controllers', []) 
    .controller('ArticleList', function($scope, $http) { 

    $scope.signIn = function() { 

     var postObject = new Object(); 
     postObject.consumer_key = pocketKey; 
     postObject.redirect_uri = "http://www.example.com"; 

     $http.post(apiUrl, postObject).success(function(data){ 
     alert(data); 
     }); 
    } 

    }) 

는 데이터처럼 보이지 않는다 실제로 게시되고있다 : 당신이 볼 수 있듯이

Request URL:https://getpocket.com/v3/oauth/request 
Request Method:OPTIONS 
Status Code:400 Bad Request 
Request Headersview source 
Accept:*/* 
Accept-Encoding:gzip,deflate,sdch 
Accept-Language:en-US,en;q=0.8 
Access-Control-Request-Headers:accept, origin, x-requested-with, content-type 
Access-Control-Request-Method:POST 
Cache-Control:no-cache 
Connection:keep-alive 
Host:getpocket.com 
Origin:http://pocket.dev:8000 
Pragma:no-cache 
Referer:http://pocket.dev:8000/app/index.html 
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36 
Response Headersview source 
Cache-Control:private 
Connection:keep-alive 
Content-Length:15 
Content-Type:text/html; charset=UTF-8 
Date:Wed, 24 Jul 2013 17:18:04 GMT 
P3P:policyref="/w3c/p3p.xml", CP="ALL CURa ADMa DEVa OUR IND UNI COM NAV INT STA PRE" 
Server:Apache/2.2.25 (Amazon) 
Status:400 Bad Request 
X-Error:Missing consumer key. 
X-Error-Code:138 
X-Powered-By:PHP/5.3.27 
X-Source:Pocket 

는 X-오류 "소비자의 키를 누락되어 "데이터가 올바르게 게시되고 있지 않음을 나타냅니다.

+2

[AngularJS의 복제본이 교차 원점 자원에 대한 OPTIONS HTTP 요청을 수행함] (http://stackoverflow.com/questions/12111936/angularjs-performs-an-options-http-request-for-a-cross-origin- 리소스) – Stewie

답변

1

코드에이 줄을 추가하십시오.

$ http.defaults.headers.post [ "콘텐츠 유형은 '= 가"은 application/x-www-form-urlencoded로는 ";

수정 코드는 다음과 같습니다.

angular.module ('pocket.controllers'[]) .controller ('ArticleList' 함수 ($ 범위, $ HTTP) {

$scope.signIn = function() { 

    var postObject = new Object(); 
    postObject.consumer_key = pocketKey; 
    postObject.redirect_uri = "http://www.example.com"; 
    $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded"; 
    $http.post(apiUrl, postObject).success(function(data){ 
    alert(data); 
    }); 
} 

})

+0

그 중 하나가 작동하지 않습니다, 나는 그것이 뭔가가 그들의 서버와 함께 할 생각 CORS를 이식하므로 원본 교차 POST 요청을 처리 할 수 ​​없습니다. – jmohsenin

+0

단일 도메인에서이 작업을 수행하고 있습니까, 아니면 도메인 간 POST 요청을 받고 있습니까? – BKM

+0

아니요, 이것은 Pocket API에 대한 도메인 간 요청입니다. http://getpocket.com/developer/docs/authentication – jmohsenin

관련 문제