|
提需求
联系方式: |
376797673 |
金额: |
50 元 |
post登录成功后 带cookie get首页不成功
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApp2
{
class Program
{
public static CookieContainer Mycookie = new CookieContainer();
public static string cookie;
static void Main(string[] args)
{
string name = get("http://www.600w.info/login");
Regex rx = new Regex("<input type=\"hidden\" name=\"hashcode\" value=\"(.*?)\" />");
Match match = rx.Match(name);
string dianer = match.Groups[1].Value;
Console.Write(post("http://www.600w.info/login", "forward=&dosubmit=1&hashcode=" + dianer + "&username=juntuantest&password=123456&code="));
Console.Write(get("http://www.600w.info/"));
Console.ReadKey();
}
public static string get(string url)
{
HttpWebRequest http = (HttpWebRequest)WebRequest.Create(url);
http.Method = "GET";
http.Host = "www.600w.info";
http.Headers.Add("Upgrade-Insecure-Requests", "1");
http.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36";
http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
http.Referer = "http://www.600w.info/login";
http.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
Mycookie = http.CookieContainer;
HttpWebResponse re = (HttpWebResponse)http.GetResponse();
StreamReader item = new StreamReader(re.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
return item.ReadToEnd();
}
public static string post(string url, string postdata)
{
HttpWebRequest http = (HttpWebRequest)WebRequest.Create(url);
http.Method = "POST";
http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
http.Referer = "http://www.600w.info/login";
http.ContentType = "application/x-www-form-urlencoded";
http.CookieContainer = Mycookie;
http.AllowAutoRedirect = true;
StreamWriter writer = new StreamWriter(http.GetRequestStream());
writer.Write(postdata);
writer.Flush();
HttpWebResponse re = (HttpWebResponse)http.GetResponse();
StreamReader item = new StreamReader(re.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
return item.ReadToEnd();
}
}
}
|
|