CHPP Development/C: Difference between revisions
From Hattrick
Jump to navigationJump to search
RebelClown (talk | contribs) No edit summary |
No edit summary |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
Step 1 | Step 1) Connecting to a recommended [[Server]] | ||
static public String getRecommendedServer() | static public String getRecommendedServer() | ||
| Line 13: | Line 13: | ||
Step 2 | Step 2) Sign-In | ||
CookieCollection CookiesCol; | CookieCollection CookiesCol; | ||
Latest revision as of 14:04, 11 February 2008
Step 1) Connecting to a recommended Server
static public String getRecommendedServer()
{
DataSet xmlDataSet = new DataSet();
DataTable xmlDataTable = new DataTable();
xmlDataSet.ReadXml("http://www.hattrick.org/common/menu.asp?outputType=XML");
xmlDataTable = xmlDataSet.Tables[0];
DataRow [] xmlDataRow = xmlDataTable.Select("", "",DataViewRowState.CurrentRows);
return (xmlDataRow[0]["RecommendedURL"].ToString());
}
Step 2) Sign-In
CookieCollection CookiesCol;
public String signIn()
{
try
{
String userName = "YOURUSERNAME";
String securityCode = "YOURPASSWORD";
String myUserAgent = "YOURAPPNAME/v1.0";
string lcUrl = recommendedURL + "/common/default.aspoutputType=XML&actionType=login&loginType=CHPP&Loginname=" +
userName + "&readonlypassword=" + securityCode;
HttpWebRequest loHttp = loHttp = (HttpWebRequest)WebRequest.Create(lcUrl);
loHttp.UserAgent = myUserAgent;
loHttp.CookieContainer = new CookieContainer();
if (CookiesCol != null && CookiesCol.Count > 0)
loHttp.CookieContainer.Add(CookiesCol);
HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();
CookiesCol = loWebResponse.Cookies;
if (loWebResponse.Cookies.Count > 0)
CookiesCol = loWebResponse.Cookies;
Encoding enc = Encoding.GetEncoding(1252);
StreamReader loResponseStream = new StreamReade(loWebResponse.GetResponseStream (), enc);
String lcHtml = loResponseStream.ReadToEnd();
loWebResponse.Close();
loResponseStream.Close();
return lcHtml;
}
catch (Exception e)
{
return e.Message;
}
}