如何使用C#登录android market?

如何使用C#登录android market?,c#,login,google-play,webrequest,C#,Login,Google Play,Webrequest,我想用C#登录到这个网页。我花了一整天的时间阅读HTTP请求和POST数据,但似乎什么都不起作用。我能做的就是阅读包含谷歌登录表单的网页。但是在登录后阅读页面似乎是不可能的 谁能告诉我怎么做 顺便说一句:我试过的代码如下所示: string mail = "XXXXXXXXXX@gmail.com"; string pw = "XXXXXXXXXX"; // Create a request using a URL that can receive a post. WebRequest re

我想用C#登录到这个网页。我花了一整天的时间阅读HTTP请求和POST数据,但似乎什么都不起作用。我能做的就是阅读包含谷歌登录表单的网页。但是在登录后阅读页面似乎是不可能的

谁能告诉我怎么做

顺便说一句:我试过的代码如下所示:

string mail = "XXXXXXXXXX@gmail.com";
string pw = "XXXXXXXXXX";

// Create a request using a URL that can receive a post. 
WebRequest request = WebRequest.Create (@"https://market.android.com/publish");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = String.Format ("Email={0}&Passwd={1}&signIn=Sign+in", mail, pw);
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();

您需要创建一个
CookieContainer
实例,并将其分配给每个请求中的
CookieContainer
属性

这将存储登录cookie,以便站点知道您仍在登录。

我通常做的是:获取并记录浏览器发送的请求。然后简单地在代码中重复这一点

例如,android marketplace与您的代码非常不同

它实际上发布到:
https://accounts.google.com/ServiceLoginAuth


并发布数据
continue=https%3A%2F%2Fmarket.android.com%2Fpublish%2FHome&followup=https%3A%2F%2Fmarket.android.com%2fpush%2FHome&service=androiddeveloper&nui=1&dsh=&GALX=&pstMsg=1&dnConn=&timeStmp=&secTok=&Email=Passwd=&signIn=
该站点可能会发送一个身份验证cookie,为了保持身份验证,您必须在后续请求中使用。好的,我补充了这一点。再加上下面罗恩的回答,事情似乎开始起作用了。但现在谷歌给了我一个“cookie功能已关闭。请打开它。”我请求的结果。还有什么我需要考虑的吗?他们可能想要一个cookie,当你请求登录页面时,它会被设置。你能再详细说明一下吗?因为事实上我以为这就是我在做的?