How to login to a spring security login form using cURL?

后端 未结 6 1809
谎友^
谎友^ 2020-12-14 08:14

I am working on a springMVC project in which the user authentication is based on spring security.

the idea is to have a mobile (android) application to be able to se

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 09:05

    It's not enough for me to use just -d options. Our web application is hosted by Tomcat, located in webapps/ROOT folder and have the following configuration:

    
    
    
    
    
        
    
    

    The following works to send POST request to our web application (assuming Tomcat is listening on port 8080):

    curl -i -H "Content-Type: application/x-www-form-urlencoded" -c cookies.txt -H "Origin: http://localhost:8080/" -d "j_username=USERNAME&j_password=PASSWORD" -X POST http://localhost:8080/j_spring_security_check
    curl -i -d @JSON_FILE -H "Content-Type: application/json" -H "Origin: http://localhost:8080/" -b cookies.txt -X POST http://localhost:8080/URL
    

    Replace USERNAME, PASSWORD, JSON_FILE and URL with your own.

提交回复
热议问题