I want to login to any website using curl on my terminal. Lets say the site is openstudy.com I am giving: curl http://www.openstudy.com -d "username=atlas" -d "password=mypassword" -v The server is sending me HTTP/1.1 302 Found.......Can anyone tell me what am I doing wrong?
actually the names of the login fields are not "username" and "password" thats why its not working , because there is no field in the login form with these names , if u inspect the site using inspector then the name of username field is something like "FX1243434334F" which is a random alphanumerical word generated by Javascript everytime u refresh the page. so ur curl statement should be like curl " http://openstudy.com " -d then that Random Field name = atlas and Random PasswordFieldName = urpassword. So in other words u cant really login into this site using this method as u cant predetermine the Field Names. To achieve the desired result u can use librarires some programming language like python(requests or mechanize) , or java(HtmlUnit or Httpunit)
while on some other sites , which have field name as "username" and "password" ur curl statement will work and U can login
oh ok...........let me have a look
Yes you are right............but isn't there any method in curl to determine field names using field labels
i m afraid not. But u can use some high level libraries that will give u the desired result.In python it could be done with just 5 lines of code.
heres what u can do. Use a HtmlParsing library (lxml.html if u r gonna use python) , select the form on the page with index 0 and then post the data.Try to do this with python and u can ask me if u have any errors doing that. um thats all
ok let me try
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html This explains the return codes for http.
I know that the 302 is the return code for redirecting to a location
Join our real-time social learning platform and learn together with your friends!