私はangularJsのヘッダーでデータを投稿しようとしています。
ヘッダなしのデータを投稿すると、サーバ側でデータを取得できます。
return $http.post('http://localhost:53646/Login', data, { headers: { "Content-Type": "application/x-www-form-urlencoded" } }
).then(function (response) {
debugger;
console.log(response.data);
return response.data;
}, function (error) {
debugger;
console.log(error);
});
しかし、カスタムヘッダーでデータを送信すると、ヘッダーとデータの両方が取得されません。
return $http.post('http://localhost:53646/Login', data, { headers: { "Content-Type": "application/x-www-form-urlencoded","Authorization":" Basic a3VtYXW1pdCsxQHJhbm9zeXMuY29tOlBhc3N3b3JkQDEyMzpJb3NBcHA" } }
).then(function (response) {
debugger;
console.log(response.data);
return response.data;
}, function (error) {
debugger;
console.log(error);
});
実際に受け取ったエラーは何ですか? ASP.NETエンドポイントはリクエストを受信していますか? – Linvi
シングルリクエストかすべてのリクエストですか? –
共通の認証ヘッダーを使用しないでください。 $ httpProvider.defaults.headers.common ['Authorization'] = "ここにデータを渡す"; return $ http.post( 'http:// localhost:53646/Login'、データ、ヘッダー:{"Content-Type": "アプリケーション/ x-www-form-urlencoded"}} ).then(関数(応答){ デバッガ; にconsole.log(response.data); 戻りresponse.data; }、関数(誤差){ デバッガ; にconsole.log(エラー); })。 –