|
1金钱
Encoding encode = Encoding.UTF8;
String user = HttpUtility.UrlEncode("xxx", encode);
String dd = HttpUtility.UrlEncode("登录", encode);
string postData = "user_login=" + user;
postData += ("&user_pass=xxx");
postData += ("&wp-submit=" + dd);
postData += ("&__hash__=26c195011eb814730c7f1d9246f13782");
byte[] data = encode.GetBytes(postData); // Prepare web request...
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://xxx.org/login/dologin/redirect/");
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.ContentLength = data.Length;//
myHttpWebRequest.Method = "POST";
Stream newStream = myHttpWebRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close(); // 服务器返回登录正确的信息
1.在getRequestStream的时候是不是就已经开始请求了。(从封包里面看到close()完毕后服务器就发回登陆成功的提示。)
2.如果上一步为真,那么close()等于参数写入完毕,也就是请求完毕, 我怎么得到这里面的内容。
如果getResponse()的话会重新请求不带cookie,失去登录状态
怎么做。。。
//登录正确的封包信息
HTTP/1.1 302 Moved Temporarily
Date: Sun, 10 Aug 2014 06:25:51 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=sk232m5l916ck9qh4ult569t53; path=/
Set-Cookie: think_template=default; expires=Sun, 10-Aug-2014 07:25:52 GMT; path=/
Location: /Index/index/婀胯韩鐔?60/
Vary: Accept-Encoding
Content-Length: 0
Connection: close
Content-Type: text/html
|
最佳答案
查看完整内容
直接用的Httphelper就是了,result.header["location"]就可以取到,只要你获取的对,,在request.GetResponse()之后就可以提取了,不需要管其他的,但一定也要在Close之前
|