0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Angular POSTでXSRFに引っかからないようにするには

0
Posted at

Angular4 + Django Rest Framework

DjangoからAngularが提供されている場合。

app.module.tsに

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {HttpModule , XSRFStrategy , CookieXSRFStrategy } from '@angular/http'
                  // ^^^^^^^^^^^    ^^^^^^^^^^^^^^^^^^ この2つのモジュールを追加
import { AppComponent } from './app.component';

import { AppService } from './app.service'
...
省略
...

@NgModule({
  
...省略

  providers: [AppService , 
      { provide : XSRFStrategy, useValue: new CookieXSRFStrategy('CSRF-TOKEN' , 'X-CSRF-TOKEN')}
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^これ追加^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ],

...省略

でPostリクエストが通りました!

Angular勉強するには、この本最高です。
Angularアプリケーションプログラミング

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?