开发者

Curl CLI - Saving Cookies PLUS login

开发者 https://www.devze.com 2023-03-06 16:07 出处:网络
The Manual at http://curl.haxx.se/docs/manual.html is a bit \"quick\" and I didn\'t get how to do do this.

The Manual at http://curl.haxx.se/docs/manual.html is a bit "quick" and I didn't get how to do do this.

I need to save all cokies (and sessions cookies) and then login to a site via CLI.

Till here, it seams it works (saving and reading):

curl -b cookies -c cookies http://www.theknot.com

Tried to use NETRC (a file ".netrc" with user and password in the format: machine curl.haxx.se login iamdaniel password开发者_运维问答 mysecret):

curl -n -L -b cookies -c cookies http://global.theknot.com/join/memberlogin.aspx

But it does not do the magic:

curl -L -n -b cookies -c cookies http://www.theknot.com/wedding-dress/mon-cheri-bridals/211249?src=par

For it keeps redirecting to the login page...

Does anybody has already been throught this? Thanks.


That's not the type of login you want. What you need to send post data directly to whatever script handles login. To send post data specifically:

4.2 POST The GET method makes all input field names get displayed in the URL field of your browser. That's generally a good thing when you want to be able to bookmark that page with your given data, but it is an obvious disadvantage if you entered secret information in one of the fields or if there are a large amount of fields creating a very long and unreadable URL. The HTTP protocol then offers the POST method. This way the client sends the data separated from the URL and thus you won't see any of it in the URL address field. The form would look very similar to the previous one:

    <form method="POST" action="junk.cgi">
      <input type=text name="birthyear">
      <input type=submit name=press value=" OK ">
    </form>
And to use curl to post this form with the same data filled in as

before, we could do it like:

    curl --data "birthyear=1905&press=%20OK%20"       

http://www.example.com/when.cgi This kind of POST will use the Content-Type
application/x-www-form-urlencoded and is the most widely used POST kind. The data you send to the server MUST already be properly encoded, curl will not do that for you. For example, if you want the data to contain a space, you need to replace that space with %20 etc. Failing to comply with this will most likely cause your data to be received wrongly and messed up. Recent curl versions can in fact url-encode POST data for you, like this:

    curl --data-urlencode "name=I am Daniel" http://www.example.com

Source: http://curl.haxx.se/docs/httpscripting.html

0

精彩评论

暂无评论...
验证码 换一张
取 消