我一直在试图弄清楚为什么这个post方法没有通过。 我一直在使用Fiddler,并且已经进行了数小时的研究。 如果有人可以帮助那将是很好。

private string getemail(string user, string pass)
{
    var cookies = new CookieContainer();

    var getRequest = (HttpWebRequest)WebRequest.Create("http://account.mojang.com/migrate");
    cookies = (getRequest as HttpWebRequest).CookieContainer;
    string[] tok = ReadResponse(getRequest).Split(new string[] { "name=\"authenticityToken\" value=\"" }, StringSplitOptions.None);
    string[] toke = tok[1].Split('"');
    string token = toke[0];

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://account.mojang.com/migrate/check");
    request.CookieContainer = cookies;
    request.Method = "POST";
    request.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    request.Headers.Add("Accept-Encoding: gzip,deflate,sdch");
    request.Headers.Add("Accept-Language: en-US,en;q=0.8");
    request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31";
    request.ContentType = "text/plain";
    using (var requestStream = request.GetRequestStream())
    {
        using (var writer = new StreamWriter(requestStream))
        {
            writer.Write("authenticityToken=" + token + "&mcusername=" + user + "&password=" + pass);
        }
    }
    using (var responseStream = request.GetResponse().GetResponseStream()) 
    {
        using (var reader = new StreamReader(responseStream))
        {
            var result = reader.ReadToEnd();
            return result;
        }
    }

}

===============>>#1 票数:0

将内容写入请求流后,关闭您的StreamWriter

using (var writer = new StreamWriter(requestStream))
{
  writer.Write("authenticityToken=" + token + "&mcusername=" + user + "&password=" + pass);
  writer.Close();
}

  ask by user2081191 translate from so

未解决问题?本站智能推荐: