How to use curl with Django, csrf tokens and POST requests

前端 未结 6 2036
一个人的身影
一个人的身影 2020-12-07 13:10

I\'m using curl to test one of my Django forms. The calls I\'ve tried (with errors from each, and over multiple lines for readability):

(1):

curl
-d          


        
6条回答
  •  春和景丽
    2020-12-07 13:57

    curl-auth-csrf is a Python-based open-source tool capable of doing this for you: "Python tool that mimics cURL, but performs a login and handles any Cross-Site Request Forgery (CSRF) tokens. Useful for scraping HTML normally only accessible when logged in."

    This would be your syntax:

    echo -n YourPasswordHere | ./curl-auth-csrf.py -i http://127.0.0.1:8083/registrations/register/ -d 'email=test@test.com&a=1' http://127.0.0.1:8083/registrations/register/
    

    This will pass along the POST data as listed, but also to include the password passed via stdin. I assume that the page you visit after "login" is the same page.

    Full disclosure: I'm the author of curl-auth-csrf.

提交回复
热议问题