二种。均是登录后。取cookies的。
第一种:
import console; import inet.whttp; whttp = inet.whttp(); var tmptab,cookietab = {},{} whttp.afterSend = function(statusCode,contentLength){ whttp.readHeader() for m in string.gmatch(whttp.responseHeaders ,"Set-Cookie\:\s*(.*?);") { tmptab = string.split(m,"=",2) if(#tmptab == 2){ cookietab[tmptab[1]] = tmptab[2] } } whttp.cookies = "" for(k,v in cookietab){ whttp.cookies += k+"="+v+"; " } } whttp.get("http://aa.com/dede/login.php") html = whttp.post( "http://aa.com/dede/login.php", { userid="testqq"; pwd="testqq"; dopost="login"; adminstyle="newdedecms"; } ); if( string.indexOf( html , "成功登录" ) ){ console.log( "成功登录" ); } console.log(whttp.cookies) var whttp2 = inet.whttp() whttp2.beforeSend = function(){ whttp2.writeHeader("Cookie:"+whttp.cookies) } html = whttp2.get("http://aa.com/dede/index.php",''); console.log( html ); console.pause();
第二种:
import console; getMyCookies = function( cks ){ result =""; try{ a1 = (string.match(cks,"PHPSESSID=([^;]+);")); a2 = (string.match(cks,"DedeUserID=([^;]+);")); a3 = (string.match(cks,"DedeUserID__ckMd5=([^;]+);")); a4 = (string.match(cks,"DedeLoginTime=([^;]+);")); a5 = (string.match(cks,"DedeLoginTime__ckMd5=([^;]+)")); cks = "PHPSESSID="++a1++"; DedeUserID="++a2++"; DedeUserID__ckMd5="++a3++"; DedeLoginTime="++a4++"; DedeLoginTime__ckMd5="++a5++"; "; result = cks; } return ""; } import inet.whttp; whttp = inet.whttp(); cookies = null; whttp.afterSend = function(statusCode,contentLength){ if( !cookies ) cookies = whttp.readHeader(); else { cookies = cookies ++ '\r\n' ++ whttp.readHeader(); } } html = whttp.get( "http://aa.com/dede/login.php"); html = whttp.post( "http://aa.com/dede/login.php", { userid="testqq"; pwd="testqq"; dopost="login"; adminstyle="newdedecms"; } ); if( string.indexOf( html , "成功登录" ) ){ console.log( "成功登录" ); } console.varDump( cookies ) cookies = getMyCookies( cookies ); console.log( cookies ); //whttp.beforeSend = function(){ whttp.writeHeader("Cookie: " ++ cookies ); } html = whttp.post("http://aa.com/dede/index.php",''); console.log( html ); console.pause();
发表评论