如何使用c#登录android市场

本文关键字:android 市场 登录 何使用 | 更新日期: 2023-09-27 18:13:36

我想使用c#登录网页Android Market。我花了一整天的时间阅读有关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 ();

如何使用c#登录android市场

我通常做的是:获取firefox的实时http头,然后你可以记录浏览器发送的请求。然后简单地在代码中重复。

例如,android marketplace的做法与你的代码完全不同。

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

并发布数据continue=https%3A%2F%2Fmarket.android.com%2Fpublish%2FHome&followup=https%3A%2F%2Fmarket.android.com%2Fpublish%2FHome&service=androiddeveloper&nui=1&dsh=&GALX=&pstMsg=1&dnConn=&timeStmp=&secTok=&Email=Passwd=&signIn=

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

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