/// <summary>Gets the HTTP cookie header that contains the HTTP cookies that represent the <see cref="T:System.Net.Cookie" /> instances that are associated with a specific URI.</summary>
/// <returns>An HTTP cookie header, with strings representing <see cref="T:System.Net.Cookie" /> instances delimited by semicolons.</returns>
/// <param name="uri">The URI of the <see cref="T:System.Net.Cookie" /> instances desired. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="uri" /> is null. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
public string GetCookieHeader(System.Uri uri)
{
if (uri == null)
{
throw new ArgumentNullException("uri");
}
CookieCollection cookieCollection = this.GetCookies(uri);
if (cookieCollection.Count == 0)
{
return(string.Empty);
}
StringBuilder stringBuilder = new StringBuilder();
foreach (object obj in cookieCollection)
{
Cookie cookie = (Cookie)obj;
stringBuilder.Append(cookie.ToString(uri));
stringBuilder.Append("; ");
}
if (stringBuilder.Length > 0)
{
stringBuilder.Length -= 2;
}
return(stringBuilder.ToString());
}