我想用C#登录到网页Android Market。我花了整整一天的时间阅读关于HTTP请求和POST数据,但似乎没有任何工作。我可以做的是阅读包含Google登录表单的网页。但阅读页面后登录似乎是不可能的...如何使用C#登录Android市场?
任何人都可以给我一个提示如何做到这一点?
BTW:我已经试过代码如下所示:
string mail = "[email protected]";
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();
该网站可能会发送一个验证cookie,你必须按顺序使用后续请求继续验证。 – driis