Root Core
Feb 18th, 2006, 07:44 PM
Well I wrote out this function for an HTTP Wrapper im making:
public string ExtractCookies(string strHeader)
{
string[] SplitStr;
string[] Temp;
string TempVal;
string Key;
string Value;
int i;
int TempHandler;
string strCookies;
SplitStr = strHeader.Split("\r\n");
for (i = 0; SplitStr.Length != 0; i++)
{
if (SplitStr[i].Contains("Set-Cookie"))
{
Temp = SplitStr[i].Split("Set-Cookie: ");
Temp = Temp[1].Split("=");
Key = Temp[0];
Temp = Temp[1].Split(";");
Value = Temp[0];
if (colCookies.Contains(Key))
{
TempHandler = Convert.ToInt16(Key);
TempVal = colCookies.GetByIndex(TempHandler);
if (TempVal != Value)
{
colCookies.Remove(Key);
colCookies.Add(Key, Key + "=" + Value + ";");
}
}
else
{
colCookies.Add(Key, Key + "=" + Value + ";");
}
}
}
strCookies = "";
int j;
for (j = 1; colCookies.Count != 0; j++)
{
strCookies = strCookies + colCookies.GetByIndex(j);
}
return strCookies;
}
Im fairly new to C# would someone mind pointing out whats wrong with this coding? I get an error with every one of the split actions >_< which says Argument '1': cannot convert from 'string' to 'char[]' and I get this error for the split actions aswell "The best overloaded method match for 'string.Split(params char[])' has some invalid arguments"
and I get an error in this part:
TempHandler = Convert.ToInt16(Key);
TempVal = colCookies.GetByIndex(TempHandler); which says: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
Does anyone know what Im doing wrong with the syntax?
PS: Im using Microsoft Visual C# 2005 Express Edition
public string ExtractCookies(string strHeader)
{
string[] SplitStr;
string[] Temp;
string TempVal;
string Key;
string Value;
int i;
int TempHandler;
string strCookies;
SplitStr = strHeader.Split("\r\n");
for (i = 0; SplitStr.Length != 0; i++)
{
if (SplitStr[i].Contains("Set-Cookie"))
{
Temp = SplitStr[i].Split("Set-Cookie: ");
Temp = Temp[1].Split("=");
Key = Temp[0];
Temp = Temp[1].Split(";");
Value = Temp[0];
if (colCookies.Contains(Key))
{
TempHandler = Convert.ToInt16(Key);
TempVal = colCookies.GetByIndex(TempHandler);
if (TempVal != Value)
{
colCookies.Remove(Key);
colCookies.Add(Key, Key + "=" + Value + ";");
}
}
else
{
colCookies.Add(Key, Key + "=" + Value + ";");
}
}
}
strCookies = "";
int j;
for (j = 1; colCookies.Count != 0; j++)
{
strCookies = strCookies + colCookies.GetByIndex(j);
}
return strCookies;
}
Im fairly new to C# would someone mind pointing out whats wrong with this coding? I get an error with every one of the split actions >_< which says Argument '1': cannot convert from 'string' to 'char[]' and I get this error for the split actions aswell "The best overloaded method match for 'string.Split(params char[])' has some invalid arguments"
and I get an error in this part:
TempHandler = Convert.ToInt16(Key);
TempVal = colCookies.GetByIndex(TempHandler); which says: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
Does anyone know what Im doing wrong with the syntax?
PS: Im using Microsoft Visual C# 2005 Express Edition