c++ - Can't login to website with libcurl -


i try login website 'http://dpi-env-zb9gfigdcz.elasticbeanstalk.com/sign_in' libcurl every time 404 error.

this c code login:

curl_global_init( curl_global_all ); curl * myhandle = curl_easy_init ( );  // set couple initial paramaters not need mofiy later. curl_easy_setopt(myhandle, curlopt_useragent, "mozilla/5.0 (x11; ubuntu;    linux x86_64; rv:30.0) gecko/20100101 firefox/30.0"); curl_easy_setopt(myhandle, curlopt_autoreferer, 1); curl_easy_setopt(myhandle, curlopt_followlocation, 1);  curl_easy_setopt(myhandle, curlopt_cookiejar, "m"); curl_easy_setopt(myhandle, curlopt_writefunction, writecallback); 

// struct curl_slist headers=null; // init null important // curl_slist_append(headers, "accept: text/html,application/xhtml+xml,application/xml;q=0.9,/*;q=0.8"); // curl_slist_append(headers, "accept-language: en-us,en;q=0.5"); // curl_slist_append(headers, "accept-encoding: gzip, deflate"); // curl_slist_append(headers, "content-type: application/x-www-form-urlencoded");

curl_easy_setopt(myhandle, curlopt_verbose, 1); //curl_easy_setopt(myhandle, curlopt_httpheader, headers); curl_easy_setopt(myhandle, curlopt_httpget,1);  curl_easy_setopt(myhandle, curlopt_url, "http://dpi-env-zb9gfigdcz.elasticbeanstalk.com/sign_in"); curl_easy_perform( myhandle );   char data[512]; sprintf(data, "session[username]=someuser&session[password]=somepass&authenticity_token=%s", [logintoken() utf8string]);  curl_easy_setopt(myhandle, curlopt_cookie, "m"); curl_easy_setopt(myhandle, curlopt_postfields, data); curl_easy_perform( myhandle );   readbuffer.clear(); curl_easy_setopt(myhandle, curlopt_referer, "http://dpi-env-zb9gfigdcz.elasticbeanstalk.com/sign_in"); curl_easy_perform( myhandle );    curl_easy_cleanup( myhandle ); 

hovever when i'm using command line curl login well.

in terminal: export url=http://dpi-env-zb9gfigdcz.elasticbeanstalk.com

joe@mcvirt:/tmp$ curl $url/sign_in --cookie-jar cookie | grep csrf

export authtok=4nw2ijo8/w6mt8vbrx/tx1+0efxlwcht1trliiberc/xcupwd0gpdzndcxb4gqfmqhlbjjxelvipjiueypnq1q==

joe@mcvirt:/tmp$ curl -i --cookie-jar cookie --cookie cookie --data "session[username]=someuser&session[password]=somepasss&authenticity_token=$authtok" $url/sessions http/1.1 302 found server: nginx/1.6.2 date: sat, 23 may 2015 00:03:36 gmt content-type: text/html; charset=utf-8 transfer-encoding: chunked connection: keep-alive x-frame-options: sameorigin x-xss-protection: 1; mode=block x-content-type-options: nosniff location: http://dpi-env-zb9gfigdcz.elasticbeanstalk.com/menu cache-control: no-cache set-cookie: request_method=post; path=/ set-cookie:  

r

emember_token=imtztlj1dxh4yjrxmzhpee5nvkgwc2mtrnbinfd0tjbku1frswixrek4uwtpu2w5r0jwvuzhcmtbv0jlt2k0efbfu3jqsu1rb3rpd3g2ohdzt2vfc1jnpt0i--38f285d6ce74fdf22c639af32e95839276b2d706; path=/; expires=wed, 23 may 2035 00:03:36 -0000 set-cookie: _djr_session=l2phzjdfvxriegphdkhtt2rxthjhsdbteglkdgzuafdjrjlztg9oavlhvjfuejncde9ure1uwhvkaxfvazhcc3rpewjuvmd0nujybenhzwrpsenwzxivt21it3b0aewysgtlzg9vahduzmf4r3zxodkzz25lwtltcevysmf2zgfsmvfos2w0sjjrne5ealm0axhxuvfbpt0tlxertmrjsvmzzunwujz0oepdwhznbve9pq%3d%3d--2d40f398330eb4ddc3870f01c580ddacf2d43dbf; path=/; httponly x-request-id: b45902ce-67cc-4ec7-9d73-54730f3367e0 x-runtime: 0.133561  <html><body>you being <a href="http://dpi-env-zb9gfigdcz.elasticbeanstalk.com/menu">redirected</a>.</body></html>joe@mcvirt:/tmp$     joe@mcvirt:/tmp$ cat cookie  # netscape http cookie file # http://curl.haxx.se/docs/http-cookies.html # file generated libcurl! edit @ own risk.  #httponly_dpi-env-zb9gfigdcz.elasticbeanstalk.com   false   /   false   0_djr_session   l2phzjdfvxriegphdkhtt2rxthjhsdbteglkdgzuafdjrjlztg9oavlhvjfuejncde9ure1uwhvkaxfvazhcc3rpewjuvmd0nujybenhzwrpsenwzxivt21it3b0aewysgtlzg9vahduzmf4r3zxodkzz25lwtltcevysmf2zgfsmvfos2w0sjjrne5ealm0axhxuvfbpt0tlxertmrjsvmzzunwujz0oepdwhznbve9pq%3d%3d--2d40f398330eb4ddc3870f01c580ddacf2d43dbf dpi-env-zb9gfigdcz.elasticbeanstalk.com false   /   false   0   request_method  post dpi-env-zb9gfigdcz.elasticbeanstalk.com false   /   false   2063491416  remember_token  imtztlj1dxh4yjrxmzhpee5nvkgwc2mtrnbinfd0tjbku1frswixrek4uwtpu2w5r0jwvuzhcmtbv0jlt2k0efbfu3jqsu1rb3rpd3g2ohdzt2vfc1jnpt0i--38f285d6ce74fdf22c639af32e95839276b2d706     joe@mcvirt:/tmp$ curl -x -i --cookie cookie  $url/menu http/1.1 200 ok server: nginx/1.6.2 date: sat, 23 may 2015 00:05:12 gmt content-type: text/html; charset=utf-8 transfer-encoding: chunked connection: keep-alive x-frame-options: sameorigin x-xss-protection: 1; mode=block x-content-type-options: nosniff etag: w/"3c5d78cb3b7c1a25aab5f64953035c7f" cache-control: max-age=0, private, must-revalidate set-cookie: _djr_session=dvrtmeoxqwiyedm5suvpmha4anrsrmjmyys2rdlpue4zbllzt21hz1fxnzdzejngzgcvqnzcywfirthykyt4bfzywg9sumvjc1necurvk2hmnwpzd1uratj6bmp2uwn2ug9jsep6bhpmwtb5mgo5tu5vdg9wn01yu3jyum51amzlnjfqttrsqjfaz21kqxo3su5lyklbpt0tluxsnej2otltcfn0wc9pegzpatc1eee9pq%3d%3d--16fa6bbff0f14a755333295c853be7995ed05210; path=/; httponly set-cookie: request_method=; path=/; max-age=0; expires=thu, 01 jan 1970 00:00:00 -0000 x-request-id: 3ca7343d-1cfb-4e28-ab27-14757b7017e7 x-runtime: 0.015257  <!doctype html> <html> <head>   <title>djr</title>   <link rel="stylesheet" media="all" href="/assets/application-0723cb9a2dd5a514d954f70e0fe0b89f6f9f1ae3a375c182f43b5f2b57e9c869.css" data-turbolinks-track="true" />   <script src="/assets/application-77c9624b0b1031d948f4b834f80d6d679ce2b17b94ee85a88d1a94279cd48d6d.js" data-turbolinks-track="true"></script>   <meta name="csrf-param" content="authenticity_token" /> <meta name="csrf-token" content="c9rcnnkb3h0auxpdjdjkveduubwgkiaju9s3knzny8zbyfpdsc9pgeymukdoeymvblzrjs6n7ritzeyqwbpa4q==" /> </head> <body>        <a id="logo" href="/menu">prod system</a>       <div id="welcome">         welcome, testfirst testlast       </div>            <li><a href="/menu">menu</a></li>           <li>             <a rel="nofollow" data-method="delete" href="/signout">sign out</a>           </li>          </ul>         </li>    <p> <a href="/events">list events</a> </p>      </body> </html> 


Comments