string strContent = "log=admin&pwd=221633&wp-submit=Log+In&redirect_to=http%3A%2F%2Flocalhost%2Fwordpress%2Fwp-admin%2F&testcookie=1";
MessageBox.Show(strContent);
byte[] bt = Encoding.ASCII.GetBytes(strContent); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/wordpress/wp-login.php");
request.Method = "POST"; request.CookieContainer = new CookieContainer(); request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = bt.Length;
Stream sr = request.GetRequestStream();
sr.Write(bt,0,bt.Length);
sr.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); request.CookieContainer.Add(response.Cookies);
if (response.StatusCode == HttpStatusCode.OK)
{
MessageBox.Show(response.StatusCode.ToString());
} strContent = "post_title=111&content=111&tags_input=111&action=post-quickpress-publish&quickpress_post_ID=0&_wpnonce=e089f001a0&_wp_http_referer=%2Fwordpress%2Fwp-admin%2Findex.php";
request = (HttpWebRequest)WebRequest.Create("http://localhost/wordpress/wp-admin/post.php");
MessageBox.Show(strContent);
bt = Encoding.ASCII.GetBytes(strContent);
request.Method = "POST";
request.CookieContainer = new CookieContainer();
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.ContentLength = bt.Length;
sr = request.GetRequestStream();
sr.Write(bt, 0, bt.Length);
sr.Close();
response = (HttpWebResponse)request.GetResponse(); request.CookieContainer.Add(response.Cookies); if (response.StatusCode == HttpStatusCode.OK)
{
MessageBox.Show(response.StatusCode.ToString());
}
MessageBox.Show(strContent);
byte[] bt = Encoding.ASCII.GetBytes(strContent); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/wordpress/wp-login.php");
request.Method = "POST"; request.CookieContainer = new CookieContainer(); request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = bt.Length;
Stream sr = request.GetRequestStream();
sr.Write(bt,0,bt.Length);
sr.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); request.CookieContainer.Add(response.Cookies);
if (response.StatusCode == HttpStatusCode.OK)
{
MessageBox.Show(response.StatusCode.ToString());
} strContent = "post_title=111&content=111&tags_input=111&action=post-quickpress-publish&quickpress_post_ID=0&_wpnonce=e089f001a0&_wp_http_referer=%2Fwordpress%2Fwp-admin%2Findex.php";
request = (HttpWebRequest)WebRequest.Create("http://localhost/wordpress/wp-admin/post.php");
MessageBox.Show(strContent);
bt = Encoding.ASCII.GetBytes(strContent);
request.Method = "POST";
request.CookieContainer = new CookieContainer();
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.ContentLength = bt.Length;
sr = request.GetRequestStream();
sr.Write(bt, 0, bt.Length);
sr.Close();
response = (HttpWebResponse)request.GetResponse(); request.CookieContainer.Add(response.Cookies); if (response.StatusCode == HttpStatusCode.OK)
{
MessageBox.Show(response.StatusCode.ToString());
}
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(response.Cookies);这两个地方有错。
应该是//定义一个全局变量 mycookie
private CookieContainer _mycookie = new CookieContainer();
public CookieContainer mycookie { get { return _mycookie; } set { _mycookie = value; } }
//mycookie,应该处于一个不会湮灭的进程中;
//先要GET下,获取Cookie;而后直接使用就行了;
request.CookieContainer = mycookie;
//不需要CookieContainer.Add();更何况是Add一个空的Cookies;
request.CookieContainer = mycookie;
//这样就行了,CookieContainer,自己自动添加和更新的。
如果不相同看哪里不一样.然后改过来喽
....
request = (HttpWebRequest)WebRequest.Create("http://localhost/wordpress/wp-admin/post.php");
这时候,已经是一个新的webrequest了
request.CookieContainer = new CookieContainer();这时候cookie集合是空的,要把之前获取到的add进来才行,不然你刚才登陆那一步,等于没用~~