Cookies HttpClient未获得与HttpWebRequest相同的CookieContainer

Cookies HttpClient未获得与HttpWebRequest相同的CookieContainer,cookies,windows-8,windows-runtime,httpwebrequest,httpclient,Cookies,Windows 8,Windows Runtime,Httpwebrequest,Httpclient,我在WPF中有一个应用程序,我使用HttpWebRequest在第三方网站上发布登录信息,HttpWebRequest.GetResponse工作得非常好,而且 我得到了我需要的正确饼干 工作守则如下: var cookies = new CookieContainer(); string postData = "login-passaporte=email@yahoo.com.br&senha-passaporte=PASS&urlRetorno=http://sportv.g

我在WPF中有一个应用程序,我使用HttpWebRequest在第三方网站上发布登录信息,HttpWebRequest.GetResponse工作得非常好,而且 我得到了我需要的正确饼干

工作守则如下:

var cookies = new CookieContainer();
string postData = "login-passaporte=email@yahoo.com.br&senha-passaporte=PASS&urlRetorno=http://sportv.globo.com/site/cartola-fc/&usar-sso=true&botaoacessar=acessar";
byte[] data = new UTF8Encoding().GetBytes(postData);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://loginfree.globo.com/login/438");

request.Timeout = 100000;
request.CookieContainer = cookies;
request.Method = WebRequestMethods.Http.Post;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";
request.AllowWriteStreamBuffering = true;
request.ProtocolVersion = HttpVersion.Version11;
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";

request.ContentLength = data.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

HttpWebResponse getResponse = (HttpWebResponse)request.GetResponse();
然后,当我尝试使用HttpClient为Windows 8应用商店应用程序移植此代码时,我的代码不会返回正确的记录cookie(上面代码上有9个cookie,下面只有1个cookie,与使用无效用户名或密码时得到的cookie相同)

在我看来,HttpClient.PostAsync没有将正确的信息发送到页面,但我几乎尝试了所有我知道的内容,但不知道是什么


注:此用户名和密码只是用于测试的工作帐户。

看起来我忘了将内容类型传递给我的HttpContent

要修复代码,我只需要向StringContent构造函数添加另一个参数

HttpContent content = new StringContent(postData, UTF8Encoding.UTF8, "application/x-www-form-urlencoded");
HttpContent content = new StringContent(postData, UTF8Encoding.UTF8, "application/x-www-form-urlencoded");