Ầu yeah!!!, lần đầu tiên đăng nhập thành công trên python, muốn khóc quá
c:\>python a.py
/session/csrf.json?_=1434560923287
http://daynhauhoc.com/session/csrf.json
1434560923287
FA2rK3Zv2PzJSMLCDhJBUBNnFFKPAZKZ41MelCTs9Q8=
{"user_badges":[{"id":5011,"granted_at":"2015-05-17T00:46:54.577Z","badge_id":4,
"user_id":2046,"granted_by_id":-1},{"id":4553,"granted_at":"2015-04-29T04:01:01.
360Z","badge_id":3,"user_id":2046,"granted_by_id":-1},{"id":5712,"granted_at":"2
015-05-26T02:06:19.722Z","post_id":34636,"post_number":3,"badge_id":6,"user_id":
2046,"granted_by_id":-1,"topic_id":7648}],"badges":[{"id":4,"name":"Leader","des
cription":null,"grant_count":14,"allow_title":true,"multiple_grant":false,"icon"
:"fa-user","image":null,"listable":true,"enabled":true,"badge_grouping_id":4,"sy
stem":true,"badge_type_id":1},{"id":3,"name":"Regular","description":null,"grant
_count":27,"allow_title":true,"multiple_grant":false,"icon":"fa-user","image":nu
ll,"listable":true,"enabled":true,"badge_grouping_id":4,"system":true,"badge_typ
e_id":2},{"id":6,"name":"Nice Post","description":null,"grant_count":24,"allow_t
itle":false,"multiple_grant":true,"icon":"fa-certificate","image":null,"listable
":true,"enabled":true,"badge_grouping_id":3,"system":true,"badge_type_id":3}],"b
adge_types":[{"id":1,"name":"Gold","sort_order":9},{"id":2,"name":"Silver","sort
_order":8},{"id":3,"name":"Bronze","sort_order":7}],"users":[{"id":2046,"usernam
e":"thanhmssl10","uploaded_avatar_id":2345,"avatar_template":"/user_avatar/daynh
auhoc.com/thanhmssl10/{size}/2345_1.png"},{"id":-1,"username":"system","uploaded
_avatar_id":1,"avatar_template":"/user_avatar/daynhauhoc.com/system/{size}/1_1.p
ng"}],"topics":[{"id":7648,"title":"[Tß╗öNG Hß╗óP] - C├íc k├¬nh Youtube hay nhß║
Ñt m├á bß║ín n├¬n th─âm ├¡t nhß║Ñt mß╗Öt lß║ºn trong ─æß╗¥i","fancy_title":"[Tß╗
öNG Hß╗óP] - C├íc k├¬nh Youtube hay nhß║Ñt m├á bß║ín n├¬n th─âm ├¡t nhß║Ñt mß╗Öt
lần trong đời","slug":"tong-hop-cac-kenh-youtube-hay-nhat-ma-ban-nen-tham-
it-nhat-mot-lan-trong-doi","posts_count":11}],"user":{"id":2046,"username":"than
hmssl10","uploaded_avatar_id":2345,"avatar_template":"/user_avatar/daynhauhoc.co
m/thanhmssl10/{size}/2345_1.png","name":"Thành Phạm","last_posted_at":"2015-0
6-17T15:59:26.407Z","last_seen_at":"2015-06-17T17:04:58.030Z","bio_raw":"Email:
[email protected]\n[Zít húp][2]\nSkype: thanhmssl10\n\n:blush: :sunglas
ses: :smile:\n\n\n [1]: http://facebook.com/thanhconsl\n [2]: http://github.co
m/thanhmssl10","bio_cooked":"<p>Email: [email protected]<br><a href=\"http:/
/github.com/thanhmssl10\">Zít húp</a><br>Skype: thanhmssl10</p>\n\n<p><img s
rc=\"/images/emoji/emoji_one/blush.png?v=0\" title=\":blush:\" class=\"emoji\" a
lt=\"blush\"> <img src=\"/images/emoji/emoji_one/sunglasses.png?v=0\" title=\":
sunglasses:\" class=\"emoji\" alt=\"sunglasses\"> <img src=\"/images/emoji/emoji
_one/smile.png?v=0\" title=\":smile:\" class=\"emoji\" alt=\"smile\"></p>","crea
ted_at":"2015-03-11T15:02:12.934Z","website":"http://","profile_background":"/up
loads/default/3273/406d7176adedfc2e.png","card_background":"/uploads/default/327
3/406d7176adedfc2e.png","can_edit":false,"can_edit_username":false,"can_edit_ema
il":false,"can_edit_name":false,"stats":[{"action_type":4,"count":78,"id":null},
{"action_type":5,"count":761,"id":null},{"action_type":6,"count":412,"id":null},
{"action_type":1,"count":1625,"id":null},{"action_type":2,"count":897,"id":null}
,{"action_type":7,"count":33,"id":null},{"action_type":9,"count":43,"id":null},{
"action_type":11,"count":35,"id":null}],"can_send_private_messages":false,"can_s
end_private_message_to_user":false,"bio_excerpt":"Email: [email protected]<b
r><a href=\"http://github.com/thanhmssl10\">Zít húp</a><br>Skype: thanhmssl1
0<br>\n\n[blush] [sunglasses] [smile]<br>","trust_level":4,"moderator":false,"a
dmin":false,"title":null,"badge_count":15,"custom_fields":{},"pending_count":0,"
invited_by":null,"custom_groups":[],"featured_user_badge_ids":[5011,4553,5712],"
card_badge":null}}
Đúng như dự đoán, “thủ phạm” là thằng cookies , bổ sung thêm vào câu trả lời của bác @mrphu3074
Bước 1: lấy CRFS TOKEN: 1434510080908 -> timestamp dạng milliseconds nhé. (lấy từ time của client)
[URL] http://daynhauhoc.com/session/csrf?_=1434510080908
[METHOD] GET
[HEADER]
Content-Type:application/json
X-Requested-With:XMLHttpRequest
[RESPONSE ] nhận được
{
"csrf": "StU+CWQeJ+zWEySUcn2m4Q3sP25CwlDPs62T21PRza8="
}
Nhận cookie từ server response về
Bước 2: Login
[URL] http://daynhauhoc.com/session
[METHOD] POST
[REQUEST HEADER]
X-Requested-With:XMLHttpRequest
X-CSRF-Token:StU+CWQeJ+zWEySUcn2m4Q3sP25CwlDPs62T21PRza8=
[REQUEST DATA] (form-data)
login=username|email
password=password
Gửi lại cookie về cho server