前提・実現したいこと
開発環境
monaca+onsenUI+angularJS
サーバーサイド:php
端末: ios
ログインのangularJS→php $http通信を行った際、phpから返ってきた値をcookieとして保持。
それ以降の$http通信を行う際、requestHeaderにセットして、php側での認証に使用する。
発生している問題・エラーメッセージ
ログイン時のangularJS→phpの$http.post処理では正しく値がかえってきており、
cookieの値を$cookie(ngCookie)にセットもできています。
ただ、その状態で$http.post()を行ってもcookieの値がrequestHeaderにセットされません。
そのため、status200でも、期待するresponseデータがかえって来ていない状態です。
cookieをheaderにセットするために何が必要なのでしょうか…?
angularJS
1[main.js] 2var conf = { 3 headers: { 4 'Content-type' : 'application/x-www-form-urlencoded' 5 ,'Accept' : 'application/json' 6 }, 7 transformRequest: null 8 }; 9 10/*ログインのhttp*/ 11$http.post( 12 url // ログインapiのurl 13 ,parameter 14 ,conf 15 ) .then(function(result) { 16 /* success */ 17 if(result.data.head.status == true){ 18 $cookies.put('myCookie' , result.data.data.session); /*responseの一部をcookieに保存 */ 19 /*↑ここのデータは正しく保持されている。*/ 20 }; 21 ,function(result){ 22 /* error */ 23 } 24 ); 25 26/*その次のhttp*/ 27 28$http.post( 29 url //データ検索のapiのURL 30 ,conf 31 ).then(function(result) { 32 33 /*status 200でかえって来ているが、データが取得できていない状態*/ 34} 35
angularJS
1[config.js] 2 3//configの設定 4 app.config(['$httpProvider',function($httpProvider){ 5 $httpProvider.defaults.withCredentials = true; 6 7 }])
試したこと
・withCredentials=trueの追加
・monacaデバッガー上で試しており、ビルドして試してはおりません。
あなたの回答
tips
プレビュー