0

我一直在试图弄清楚为什么这个 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;
        }
    }

}

4

1 回答 1

0

StreamWriter将内容写入请求流后关闭。

using (var writer = new StreamWriter(requestStream))
{
  writer.Write("authenticityToken=" + token + "&mcusername=" + user + "&password=" + pass);
  writer.Close();
}
于 2013-04-16T02:26:12.050 回答