110,534
社区成员
发帖
与我相关
我的任务
分享
private string contentMsg = "";//content
private void GetMsg()
{
...
try
{
HttpWebRequest requestNewGmail = WebRequest.Create(gmailUrl) as HttpWebRequest;
requestNewGmail.CookieContainer = holdCookie;
if (requestNewGmail != null)
{
using (HttpWebResponse getCreatAccountRes = requestNewGmail.GetResponse() as HttpWebResponse)
{
using (StreamReader accountInformReader =
new StreamReader(getCreatAccountRes.GetResponseStream()))
{
string resultText = accountInformReader.ReadToEnd();
//get messages
...
}
}
}
}
catch(Exception ex)
{
string tex = ex.Message;
}
}
private void CreateGmail()
{
try
{
//CreatContent
...
//我将其大致组成如下格式:
String.Format("dsh={0}&ktl={1}&ktf={2}&Email={3}&Passwd={4}"
+ "&PasswdAgain={5}&PersistentCookie={6}&rmShown={7}&nshk={8}&ie5OrAbove={9}"
+ "&loc={10}&newaccounttoken={11}&newaccounturl={12}&newaccounttoken_audio={13}"
+ "&newaccounturl_audio={14}&newaccountcaptcha={15}&privacy_policy_url={16}"
+ "&requested_tos_location={17}&requested_tos_language={18}&served_tos_location={19}"
+ "&served_tos_language={20}&submitbutton={21}",...)
byte[] content = Encoding.UTF8.GetBytes(createStr);
HttpWebRequest requestNewGmail = WebRequest.Create(gmailUrl) as HttpWebRequest;
requestNewGmail.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
requestNewGmail.KeepAlive = true;
requestNewGmail.ContentLength = content.Length;
requestNewGmail.ContentType = "application/x-www-form-urlencoded";
requestNewGmail.Method = "POST";
requestNewGmail.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
using (Stream submitSm = requestNewGmail.GetRequestStream())
{
submitSm.Write(content, 0, content.Length);
}
string tst = "";
using (HttpWebResponse createResponse = requestNewGmail.GetResponse() as HttpWebResponse)
{
using (StreamReader stsm = new StreamReader(createResponse.GetResponseStream(), Encoding.Default))
{
tst = stsm.ReadToEnd();//这里获取的页面信息和刚开始几乎一模一样,没有进入到申请成功的页面
}
}
}
catch (Exception ex)
{
string tex = ex.Message;
}
}