I implemented an application using C# and Django, and my problem is that when I login in the client the server returns everything right, the sessionid and everything but the csrf token.
I have it on my settings file in middleware_classes. Is this because im accessing the server directly through its ip address?
My django Login function
class loginMobile(GenericAPIView):
serializer_class = loginSerializer
def post(self, request):
try:
email = request.DATA.get('email')
password = request.DATA.get('password')
user_django = authenticate(username=email, password=password)
login(request, user_django)
return Response({'success': True})
except:
return Response({'success': False})
my C# request:
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
if (response.Cookies != null && response.Cookies.Count != 0)
{
this.cookie_col = response.Cookies;
this.cookies = new List<Cookie>();
foreach (Cookie c in response.Cookies)
{
this.cookies.Add(c);
if (c.Name.Equals("csrftoken"))
this.csrf_token = c.Value;
}
}
}
In "response.cookies" I only get the "sessionid" not the "csrftoken" Also this happening when I hosted the appplication in a server, it works like a charm on my local machine