110,545
社区成员
发帖
与我相关
我的任务
分享
Request URL:http://localhost/gyjw/index.php/index/login_into
Request Method:POST
Status Code:200 OK
Request Headersview parsed
POST /gyjw/index.php/index/login_into HTTP/1.1
Host: localhost
Connection: keep-alive
Content-Length: 99
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: http://localhost
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1574.0 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://localhost/gyjw/index.php/index/Index.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
Cookie: PHPSESSID=88b0mepbjeq3vv1lenl3qfv0s4
Form Dataview sourceview URL encoded
admin:admin
password:424
__hash__:9dcee4d5bcfb44270f8cbfaebbc2d786_cbebe27eff89edd8bb6e55eabf493c98
Response Headersview parsed
HTTP/1.1 200 OK
Date: Mon, 31 Mar 2014 06:27:07 GMT
Server: Apache/2.2.8 (Win32) PHP/5.2.6
X-Powered-By: ThinkPHP
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: private
Pragma: no-cache
Content-Length: 1452
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
public class SCookie
{
public CookieContainer mycookie = new CookieContainer();//定义cookie容器
public Object obj = new Object();
public byte[] byt = new byte[1];
public void upcookie(CookieCollection cookie)
{
for (int i = 0; i < cookie.Count; i++)
{
mycookie.Add(cookie[i]);
}
obj = mycookie;
byt = ObjectToBytes(obj);
}
/**/
/// <summary>
/// 将一个object对象序列化,返回一个byte[]
/// </summary>
/// <param name="obj">能序列化的对象</param>
/// <returns></returns>
public static byte[] ObjectToBytes(object obj)
{
using (MemoryStream ms = new MemoryStream())
{
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(ms, obj);
return ms.GetBuffer();
}
}
/**/
/// <summary>
/// 将一个序列化后的byte[]数组还原
/// </summary>
/// <param name="Bytes"></param>
/// <returns></returns>
public object BytesToObject(byte[] Bytes)
{
using (MemoryStream ms = new MemoryStream(Bytes))
{
IFormatter formatter = new BinaryFormatter();
return formatter.Deserialize(ms);
}
}
public CookieContainer getcookie()
{
return mycookie;
}
}
使用方法 bCookie.upcookie(myResponse.Cookies);class CookieMD
{
public static List<Cookie> GetAllCookies(CookieContainer cc)
{
List<Cookie> lstCookies = new List<Cookie>();
Hashtable table = (Hashtable)cc.GetType().InvokeMember("m_domainTable",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance, null, cc, new object[] { });
foreach (object pathList in table.Values)
{
SortedList lstCookieCol = (SortedList)pathList.GetType().InvokeMember("m_list",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField
| System.Reflection.BindingFlags.Instance, null, pathList, new object[] { });
foreach (CookieCollection colCookies in lstCookieCol.Values)
foreach (Cookie c in colCookies) lstCookies.Add(c);
}
return lstCookies;
}
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);
public static bool StartIE(CookieContainer cc,string url)
{
try
{
List<Cookie> TempCookies = CookieMD.GetAllCookies(cc);
foreach (Cookie i in TempCookies.ToArray())
{
CookieMD.InternetSetCookie(
"http://weibo.com",
i.Name.ToString(),
i.Value.ToString() + ";expires=Sun,22-Feb-2099 00:00:00 GMT");
}
Process.Start("iexplore.exe", url);
return true;
}
catch { return false; }
}
}
登录后 把cookie弄过来 try StartIE