Ionic / angularjs with django csrf running on local server but not working on device

I am working on ionic and am using Django with django-rest-framework as a backend. I tried sending to my server using $httpas follows:

$http({
  url: url,
  method: method,
  data: {
    // some data
  }
}).success...

I also installed the following in my configuration:

$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';

I also tried ngCookiesbut $cookies.csrftokenreturns nothing.

Here is my internal code:

class Mark(APIView):
    def post(self, request):
        # do something
        return Response({
            # something
        })

This works fine when I used the ion local server ionic serve, but when I create it on the iOS emulator or on my iPhone, csrf 403 appears:

{"detail":"CSRF Failed: CSRF token missing or incorrect."}

returned from the server.

Any idea on this? Thank you very much!

+4
1

, , , , . iOS cookie , window.localStorage .

. : cookie Cordova?

+6

Source: https://habr.com/ru/post/1653956/


All Articles