【发布时间】:2021-12-10 13:41:42
【问题描述】:
如何使用 Flutter HTTP 请求发送 CSRF 令牌
我有一个基于 Django 的项目,它使用 django-rest-framework 作为 API,当我使用 Postman 发送 POST 请求时,它工作得非常好,但是当我从我的颤振应用程序发送 HTTP.post 请求时,我得到了这个响应:
Forbidden 403
CSRF verification failed. Request aborted.
You are seeing this message because this HTTPS site requires a “Referer header” to be sent by your Web browser, but none was sent
在 django 中使用function based view 接收请求:
@api_view(['POST'])
@permission_classes([AllowAny,])
@csrf_exempt
def create_user(request):
......
.....
然后在URLS:
path("api/v1/create_user/", api.create_user, name="create_user"),
并且正在颤振中发送请求:
http.post(Uri(myURL),header={
'Content-Type': 'application/x-www-form-urlencoded',
}
,body={
'my_key':'my_value',
})
【问题讨论】:
-
你可以在header上传递它
-
@ArbiterChil 我什至可以从哪里得到它!如何传入标头,可以给我更多信息吗?
-
只需传递带有“Referer”键的标头,值是任何 url
-
不,它没有任何区别,同样的 403 禁止响应!
标签: python django flutter dart django-rest-framework